From 7598f649f419fa897794005c3b74d5e46852625c Mon Sep 17 00:00:00 2001 From: Michiel van den Heuvel Date: Thu, 20 Jul 2023 16:23:32 +0200 Subject: Fix filename escaping when opening a file --- init.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index ca004a5..f1d481a 100644 --- a/init.lua +++ b/init.lua @@ -399,6 +399,10 @@ local function lspc_confirm(prompt) return choice == 'yes' end +local function vis_open_file(file, cmd) + vis:command(('%s %s'):format(cmd, file:gsub('[\\\t "\']', '\\%1'):gsub('\n', '\\n'))) +end + -- open a doc_pos using the vis command local function vis_open_doc_pos(doc_pos, cmd, win) if win and win ~= vis.win then @@ -414,7 +418,7 @@ local function vis_open_doc_pos(doc_pos, cmd, win) return end end - vis:command(string.format('%s \'%s\'', cmd, doc_pos.file)) + vis_open_file(doc_pos.file, cmd) vis.win.selection:to(doc_pos.line, doc_pos.col) vis:command('lspc-open') else @@ -530,7 +534,7 @@ local function vis_apply_workspaceEdit(_, _, workspaceEdit) -- It is not open currently -> open it local opened if not win_with_file then - vis:command('o ' .. path) + vis_open_file(path, 'o') win_with_file = vis.win opened = true end -- cgit v1.2.3