From 2999fa13ee7860a39a0b07a74dbf6dc52bfd83ae Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sat, 15 Apr 2023 12:07:18 +0200 Subject: jump to document position in the original window Currently if a method call result causing the editor to jump to a new location is received from the language server we change the current window ('vis.win'). However this behavior is strange if the user has already switch window the message window was opened. Remember the window where the jump was requested and execute it in the original window. --- init.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/init.lua b/init.lua index a431e79..e2a51b6 100644 --- a/init.lua +++ b/init.lua @@ -294,7 +294,10 @@ local function lsp_range_to_vis_range(win, lsp_range) end -- open a doc_pos using the vis command -local function vis_open_doc_pos(doc_pos, cmd) +local function vis_open_doc_pos(doc_pos, cmd, win) + if win and win ~= vis.win then + vis.win = win + end assert(cmd) vis:command(string.format('%s \'%s\'', cmd, doc_pos.file)) vis.win.selection:to(doc_pos.line, doc_pos.col) @@ -305,28 +308,28 @@ end -- Stack of edited document positions local doc_pos_history = {} --- Open a document position in the active window local function vis_push_doc_pos(win) local old_doc_pos = vis_get_doc_pos(win) table.insert(doc_pos_history, old_doc_pos) end -- open a new doc_pos remembering the old if it is replaced -local function vis_open_new_doc_pos(doc_pos, cmd) +local function vis_open_new_doc_pos(doc_pos, cmd, win) + win = win or vis.win if cmd == 'e' then - vis_push_doc_pos(vis.win) + vis_push_doc_pos(win) end - vis_open_doc_pos(doc_pos, cmd) + vis_open_doc_pos(doc_pos, cmd, win) end -local function vis_pop_doc_pos() +local function vis_pop_doc_pos(win) local last_doc_pos = table.remove(doc_pos_history) if not last_doc_pos then return 'Document history is empty' end - vis_open_doc_pos(last_doc_pos, 'e') + vis_open_doc_pos(last_doc_pos, 'e', win) end -- apply a textEdit received from the language server @@ -611,7 +614,7 @@ local function lspc_handle_goto_method_response(req, result) end local doc_pos = lsp_doc_pos_to_vis(lsp_doc_pos) - vis_open_new_doc_pos(doc_pos, req.ctx) + vis_open_new_doc_pos(doc_pos, req.ctx, req.win) end local function lspc_handle_completion_method_response(win, result, old_pos) -- cgit v1.2.3