diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2021-07-14 13:15:20 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2021-07-14 13:16:31 +0200 |
| commit | 60fece788c95e5e31067024cdad97e6ef256f47b (patch) | |
| tree | 22f0c4dfe12204f802504ca7a35a29fc8baa551f /init.lua | |
| parent | c1ad992c89a4f4cb79c1e2bfec25b7f5dc00c321 (diff) | |
| download | vis-lspc-60fece788c95e5e31067024cdad97e6ef256f47b.tar.gz vis-lspc-60fece788c95e5e31067024cdad97e6ef256f47b.zip | |
open and close files with changes if necessary
Diffstat (limited to 'init.lua')
| -rw-r--r-- | init.lua | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -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 |
