From e1ab18119cfafb9012723a9a41a83345161f37c5 Mon Sep 17 00:00:00 2001 From: Quinten Kock Date: Tue, 11 Jan 2022 04:16:48 +0100 Subject: [PATCH] Implement initial go-back --- lsp/init.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lsp/init.lua b/lsp/init.lua index f3137f6..bc0a569 100644 --- a/lsp/init.lua +++ b/lsp/init.lua @@ -383,6 +383,10 @@ end ---Open a document location returned by LSP ---@param location table function lsp.goto_location(location) + local source_line, source_col = core.active_view.doc:get_selection() + if not core.active_view.doc.lsp_stack then core.active_view.doc.lsp_stack = {} end + table.insert(core.active_view.doc.lsp_stack, {line = source_line, col = source_col}) + core.root_view:open_doc( core.open_doc( common.home_expand( @@ -396,6 +400,15 @@ function lsp.goto_location(location) core.active_view.doc:set_selection(line1, col1, line1, col1) end +function lsp.go_back() + if core.active_view.doc.lsp_stack then + local last = table.remove(core.active_view.doc.lsp_stack) + if last then + core.active_view.doc:set_selection(last.line, last.col, last.line, last.col) + end + end +end + lsp.get_location_preview = get_location_preview ---Register an LSP server to be launched on demand @@ -2105,6 +2118,10 @@ command.add("core.docview", { end lsp.toggle_diagnostics() end, + + ["lsp:go-back"] = function() + lsp.go_back() + end }) -- @@ -2125,6 +2142,7 @@ keymap.add { ["alt+shift+e"] = "lsp:toggle-diagnostics", ["alt+c"] = "lsp:view-call-hierarchy", ["alt+r"] = "lsp:rename-symbol", + ["alt+z"] = "lsp:go-back", } --