diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-04-15 12:07:18 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-04-15 12:07:18 +0200 |
| commit | 2999fa13ee7860a39a0b07a74dbf6dc52bfd83ae (patch) | |
| tree | f3806cfed68f49476ac49c636baa0621ee4767a4 | |
| parent | a035db0f33b2a16a67daf915cafaec3b8e8022d0 (diff) | |
| download | vis-lspc-2999fa13ee7860a39a0b07a74dbf6dc52bfd83ae.tar.gz vis-lspc-2999fa13ee7860a39a0b07a74dbf6dc52bfd83ae.zip | |
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.
| -rw-r--r-- | init.lua | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -294,7 +294,10 @@ local function lsp_range_to_vis_range(win, lsp_range) end -- open a doc_pos using the vis command <cmd> -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) |
