From b131251ad83b3a9077406955d77d7e4e6340ad0b Mon Sep 17 00:00:00 2001 From: ray-x Date: Mon, 1 Aug 2022 22:32:15 +1000 Subject: [PATCH] send floating view result to quickfix; de-duplicate references --- README.md | 1 + lua/navigator/diagnostics.lua | 4 ++-- lua/navigator/lspclient/clients.lua | 2 +- lua/navigator/reference.lua | 15 ++------------- lua/navigator/treesitter.lua | 10 +++++----- lua/navigator/util.lua | 4 +++- 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 0082cd8..cc9f514 100644 --- a/README.md +++ b/README.md @@ -488,6 +488,7 @@ In `playground` folder, there is a `init.lua` and source code for you to play wi | n | \ | open preview file in nvim/Apply action | | n | \ | close listview of floating window | | i/n | \ | close listview of floating window | +| n | \ | close listview and send results to quickfix | | i/n | \ | previous page in listview | | i/n | \ | next page in listview | | i/n | \ | save the modification to preview window to file | diff --git a/lua/navigator/diagnostics.lua b/lua/navigator/diagnostics.lua index d377cc3..e8a728f 100644 --- a/lua/navigator/diagnostics.lua +++ b/lua/navigator/diagnostics.lua @@ -66,7 +66,7 @@ local function error_marker(result, ctx, config) end if not api.nvim_buf_is_loaded(bufnr) then - log('buf not loaded', bufnr) + trace('buf not loaded', bufnr) return end @@ -187,7 +187,7 @@ local diag_hdlr = function(err, result, ctx, config) local mode = api.nvim_get_mode().mode if mode ~= 'n' and config.update_in_insert == false then - log('skip sign update in insert mode') + trace('skip sign update in insert mode') end local cwd = vim.loop.cwd() local ft = vim.bo.filetype diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index 491f036..ab7c6f2 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -643,7 +643,7 @@ local function on_filetype() return end if uri == 'file://' or uri == 'file:///' then - log('skip loading for ft ', ft, uri) + trace('skip loading for ft ', ft, uri) return end diff --git a/lua/navigator/reference.lua b/lua/navigator/reference.lua index 426e06e..66fd9ce 100644 --- a/lua/navigator/reference.lua +++ b/lua/navigator/reference.lua @@ -14,7 +14,7 @@ local ref_view = function(err, locations, ctx, cfg) local truncate = cfg and cfg.truncate or 20 local opts = {} trace('arg1', err, ctx, locations) - log(#locations, locations[1]) + -- log(#locations, locations[1]) if ctx.combine then -- wait for both reference and definition LSP request if ctx.results == nil then @@ -45,23 +45,12 @@ local ref_view = function(err, locations, ctx, cfg) if references and references.result and #references.result > 0 then local refs = references.result vim.list_extend(locations, refs) - for _, value in pairs(locations) do - local vrange = value.range or { start = { line = 0 }, ['end'] = { line = 0 } } - for i = 1, #refs, 1 do - local rg = refs[i].range or {} - trace(value, refs[i]) - trace(rg, vrange) - if rg.start.line == vrange.start.line and rg['end'].line == vrange['end'].line then - table.remove(refs, i) - break - end - end - end end err = nil trace(locations) -- lets de-dup first 10 elements. some lsp does not recognize definition and reference difference locations = util.dedup(locations) + trace(locations) end -- log("num", num) -- log("bfnr", bufnr) diff --git a/lua/navigator/treesitter.lua b/lua/navigator/treesitter.lua index ce2098c..9a31052 100644 --- a/lua/navigator/treesitter.lua +++ b/lua/navigator/treesitter.lua @@ -395,8 +395,8 @@ local function get_all_nodes(bufnr, filter, summary) for i = 1, n do local index = n + 1 - i local parent_def = parents[index] - log(parent_def.type, parent_def.node:type(), vim.treesitter.get_node_text(parent_def.node, bufnr)) - log(def.node:type(), vim.treesitter.get_node_text(def.node, bufnr)) + -- trace(parent_def.type, parent_def.node:type(), vim.treesitter.get_node_text(parent_def.node, bufnr)) + -- trace(def.node:type(), vim.treesitter.get_node_text(def.node, bufnr)) if ts_utils.is_parent(parent_def.node, def.node) or ( @@ -410,10 +410,10 @@ local function get_all_nodes(bufnr, filter, summary) ) ) then - log('is parent', i, index) + -- trace('is parent', i, index) break else - log('leave node', i, index) + -- trace('leave node', i, index) parents[index] = nil end end @@ -477,7 +477,7 @@ local function get_all_nodes(bufnr, filter, summary) trace(item.node_text, item.kind, item.type) if scope ~= nil then if not is_func and summary then - log('skipped', item.node_text, item.type) + trace('skipped', item.node_text, item.type) goto continue end item.node_scope = ts_utils.node_to_lsp_range(scope) diff --git a/lua/navigator/util.lua b/lua/navigator/util.lua index cb861e1..bb79d5d 100644 --- a/lua/navigator/util.lua +++ b/lua/navigator/util.lua @@ -504,7 +504,7 @@ function M.dedup(locations) if not range then break end - local key = (range.uri or value.targetUri or '') + local key = (value.uri or range.uri or value.targetUri or '') .. ':' .. tostring(range.start.line) .. ':' @@ -524,7 +524,9 @@ function M.dedup(locations) end end end + table.sort(del) for i = #del, 1, -1 do + M.log('remove ', del[i]) table.remove(locations, del[i]) end return locations