From 60fece788c95e5e31067024cdad97e6ef256f47b Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 14 Jul 2021 13:15:20 +0200 Subject: open and close files with changes if necessary --- init.lua | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 1ad56e9..679184c 100644 --- a/init.lua +++ b/init.lua @@ -458,20 +458,32 @@ local function vis_apply_workspaceEdit(_, _, workspaceEdit) -- apply changes to open files for uri, edits in pairs(file_edits) do local path = uri_to_path(uri) - -- local open = false + -- search all open windows for this uri + local win_with_file for win in vis:windows() do if win.file and win.file.path == path then - -- open = true - for _, edit in ipairs(edits) do - vis_apply_textEdit(win, win.file, edit) - end + win_with_file = win + break end end - -- TODO: apply changes to not open files - -- if not open then - -- end + -- It is not open currently -> open it + local opened + if not win_with_file then + vis:command('o ' .. path) + win_with_file = vis.win + opened = true + end + + for _, edit in ipairs(edits) do + vis_apply_textEdit(win_with_file, win_with_file.file, edit) + end + + -- save changes and close the opened window + if opened then + vis:command('wq') + end end end -- cgit v1.2.3