send floating view result to quickfix; de-duplicate references

fix-keymap-buffer
ray-x 2 years ago
parent 8978bdb1e3
commit b131251ad8

@ -488,6 +488,7 @@ In `playground` folder, there is a `init.lua` and source code for you to play wi
| n | \<Enter\> | open preview file in nvim/Apply action |
| n | \<ESC\> | close listview of floating window |
| i/n | \<C-e\> | close listview of floating window |
| n | \<C-q\> | close listview and send results to quickfix |
| i/n | \<C-b\> | previous page in listview |
| i/n | \<C-f\> | next page in listview |
| i/n | \<C-s\> | save the modification to preview window to file |

@ -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

@ -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

@ -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)

@ -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)

@ -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

Loading…
Cancel
Save