From 5f1506fc0cd52c44862b6b7c260c848893f64008 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Wed, 2 Mar 2022 09:55:04 -0800 Subject: [PATCH] apply cwd to path when parsing LSP URIs (#341) --- README.md | 2 +- doc/fzf-lua.txt | 2 +- lua/fzf-lua/path.lua | 15 +++++++++------ lua/fzf-lua/utils.lua | 3 +++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9d1d9ec..210aa7a 100644 --- a/README.md +++ b/README.md @@ -635,8 +635,8 @@ require'fzf-lua'.setup { file_icons = true, git_icons = false, lsp_icons = true, - severity = "hint", ui_select = true, -- use 'vim.ui.select' for code actions + severity = "hint", icons = { ["Error"] = { icon = "", color = "red" }, -- error ["Warning"] = { icon = "", color = "yellow" }, -- warning diff --git a/doc/fzf-lua.txt b/doc/fzf-lua.txt index 46cc314..357d175 100644 --- a/doc/fzf-lua.txt +++ b/doc/fzf-lua.txt @@ -677,8 +677,8 @@ Consult the list below for available settings: file_icons = true, git_icons = false, lsp_icons = true, - severity = "hint", ui_select = true, -- use 'vim.ui.select' for code actions + severity = "hint", icons = { ["Error"] = { icon = "", color = "red" }, -- error ["Warning"] = { icon = "", color = "yellow" }, -- warning diff --git a/lua/fzf-lua/path.lua b/lua/fzf-lua/path.lua index 25866c7..a9ca34e 100644 --- a/lua/fzf-lua/path.lua +++ b/lua/fzf-lua/path.lua @@ -172,15 +172,22 @@ 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) + local isURI = stripped:match("^%a+://") + -- Prepend cwd before constructing the URI (#341) + if cwd and #cwd>0 and not isURI and + not M.starts_with_separator(stripped) then + stripped = M.join({cwd, stripped}) + end -- #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 + if not isURI and force_uri then + isURI = true 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 - if not bufnr and stripped:match("^%a+://") then + if isURI and not bufnr then -- Issue #195, when using nvim-jdtls -- https://github.com/mfussenegger/nvim-jdtls -- LSP entries inside .jar files appear as URIs @@ -196,10 +203,6 @@ function M.entry_to_file(entry, cwd, force_uri) local file = s[1] local line = tonumber(s[2]) local col = tonumber(s[3]) - if cwd and #cwd>0 and not M.starts_with_separator(file) then - file = M.join({cwd, file}) - stripped = M.join({cwd, stripped}) - end local terminal if bufnr then terminal = utils.is_term_buffer(bufnr) diff --git a/lua/fzf-lua/utils.lua b/lua/fzf-lua/utils.lua index 97efea9..32f3422 100644 --- a/lua/fzf-lua/utils.lua +++ b/lua/fzf-lua/utils.lua @@ -210,6 +210,9 @@ M.read_file_async = function(filepath, callback) end +-- deepcopy can fail with: "Cannot deepcopy object of type userdata" (#353) +-- this can happen when copying items/on_choice params of vim.ui.select +-- run in a pcall and fallback to our poor man's clone function M.deepcopy(t) local ok, res = pcall(vim.deepcopy, t) if ok then