From a487c6752f2ac3699ecf2f906be4e02fdff05c7a Mon Sep 17 00:00:00 2001 From: bhagwan Date: Sat, 5 Feb 2022 11:29:35 -0800 Subject: [PATCH] force LSP jumps to use 'vim.lsp.util.jump_to_location' (closes #336) --- lua/fzf-lua/actions.lua | 2 +- lua/fzf-lua/path.lua | 7 ++++++- lua/fzf-lua/providers/lsp.lua | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lua/fzf-lua/actions.lua b/lua/fzf-lua/actions.lua index fe41172..d5f1558 100644 --- a/lua/fzf-lua/actions.lua +++ b/lua/fzf-lua/actions.lua @@ -85,7 +85,7 @@ M.vimcmd_file = function(vimcmd, selected, opts) local curbuf = vim.api.nvim_buf_get_name(0) local is_term = utils.is_term_buffer(0) for i = 1, #selected do - local entry = path.entry_to_file(selected[i]) + local entry = path.entry_to_file(selected[i], opts.cwd, opts.force_uri) entry.ctag = path.entry_to_ctag(selected[i]) -- Java LSP entries, 'jdt://...' if entry.uri then diff --git a/lua/fzf-lua/path.lua b/lua/fzf-lua/path.lua index 2e7a84b..aa5943b 100644 --- a/lua/fzf-lua/path.lua +++ b/lua/fzf-lua/path.lua @@ -168,10 +168,15 @@ function M.entry_to_location(entry) } end -function M.entry_to_file(entry, cwd) +function M.entry_to_file(entry, cwd, force_uri) -- Remove ansi coloring and prefixed icons entry = utils.strip_ansi_coloring(entry) local stripped, idx = stripBeforeLastOccurrenceOf(entry, utils.nbsp) + -- #336: force LSP jumps using 'vim.lsp.util.jump_to_location' + -- so that LSP entries are added to the tag stack + if force_uri and not stripped:match("^%a+://") then + stripped = "file://" .. stripped + end -- entries from 'buffers' contain '[]' -- buffer placeholder always comes before the nbsp local bufnr = idx>1 and entry:sub(1, idx):match("%[(%d+)") or nil diff --git a/lua/fzf-lua/providers/lsp.lua b/lua/fzf-lua/providers/lsp.lua index 977b5b4..1926957 100644 --- a/lua/fzf-lua/providers/lsp.lua +++ b/lua/fzf-lua/providers/lsp.lua @@ -295,6 +295,7 @@ local function fzf_lsp_locations(opts) opts = normalize_lsp_opts(opts, config.globals.lsp) if not opts then return end opts = core.set_fzf_line_args(opts) + if opts.force_uri == nil then opts.force_uri = true end opts = set_lsp_fzf_fn(opts) if not opts.fzf_fn then return end return core.fzf_files(opts) @@ -335,6 +336,7 @@ M.workspace_symbols = function(opts) if not opts then return end opts.lsp_params = {query = opts.query or ''} opts = core.set_fzf_line_args(opts) + if opts.force_uri == nil then opts.force_uri = true end opts = set_lsp_fzf_fn(opts) if not opts.fzf_fn then return end return core.fzf_files(opts) @@ -617,6 +619,7 @@ M.diagnostics = function(opts) end opts = core.set_fzf_line_args(opts) + if opts.force_uri == nil then opts.force_uri = true end return core.fzf_files(opts) end @@ -677,6 +680,7 @@ M.live_workspace_symbols = function(opts) opts.__FNCREF__ = M.live_workspace_symbols opts = core.set_fzf_interactive_cb(opts) opts = core.set_fzf_line_args(opts) + if opts.force_uri == nil then opts.force_uri = true end core.fzf_files(opts) opts.search = nil end