From 18f230b4d239cd391b581c50724366ea253f5ed1 Mon Sep 17 00:00:00 2001 From: Michiel van den Heuvel Date: Tue, 4 Feb 2025 14:10:40 +0100 Subject: Coalesce some event subscriptions --- init.lua | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index b8986a4..fd8c0b4 100644 --- a/init.lua +++ b/init.lua @@ -1212,21 +1212,6 @@ local function lspc_open(ls, win, file) ls:send_notification('textDocument/didOpen', params) - vis.events.subscribe(vis.events.FILE_CLOSE, function(closed_file) - lspc_close(ls, closed_file) - end) - - -- the server is interested in didSave notifications - if ls.capabilities.textDocumentSync and type(ls.capabilities.textDocumentSync) == 'table' and - ls.capabilities.textDocumentSync.save then - vis.events.subscribe(vis.events.FILE_SAVE_POST, function(saved_file, path) - if ls:is_file_opened(saved_file) then - local did_save_params = {textDocument = {uri = path_to_uri(path)}} - ls:send_notification('textDocument/didSave', did_save_params) - end - end) - end - vis.events.emit(lspc.events.LS_DID_OPEN, ls, file) end @@ -1766,8 +1751,26 @@ vis.events.subscribe(vis.events.FILE_SAVE_POST, function(file, path) if not file_handle then return end + for ls in pairs(file_handle.language_servers) do ls:send_did_change(file) + -- the server is interested in didSave notifications + if ls.capabilities.textDocumentSync and type(ls.capabilities.textDocumentSync) == 'table' and + ls.capabilities.textDocumentSync.save then + local did_save_params = {textDocument = {uri = path_to_uri(file.path)}} + ls:send_notification('textDocument/didSave', did_save_params) + end + end +end) + +vis.events.subscribe(vis.events.FILE_CLOSE, function(closed_file) + local file_handle = lspc.open_files[closed_file.path] + if not file_handle then + return + end + + for ls in pairs(file_handle.language_servers) do + lspc_close(ls, closed_file) end end) -- cgit v1.2.3