aboutsummaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2021-07-14 13:15:20 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2021-07-14 13:16:31 +0200
commit60fece788c95e5e31067024cdad97e6ef256f47b (patch)
tree22f0c4dfe12204f802504ca7a35a29fc8baa551f /init.lua
parentc1ad992c89a4f4cb79c1e2bfec25b7f5dc00c321 (diff)
downloadvis-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.lua28
1 files changed, 20 insertions, 8 deletions
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