From a93f7cb20f2b13fab8618c0b53befa1fc8ea68b0 Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 7 Jul 2022 10:18:15 +1000 Subject: [PATCH] dedup reference results --- lua/navigator/reference.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lua/navigator/reference.lua b/lua/navigator/reference.lua index 5571bd3..5686387 100644 --- a/lua/navigator/reference.lua +++ b/lua/navigator/reference.lua @@ -59,6 +59,35 @@ local ref_view = function(err, locations, ctx, cfg) end err = nil trace(locations) + -- lets de-dup first 10 elements. some lsp does not recognize definition and reference difference + local m = 10 + if 10 > #locations then + m = #locations + end + + local dict = {} + local del = {} + for i = 1, m, 1 do + local value = locations[i] + if not value.range then + break + end + local key = (value.range.uri or value.targetUri or "") .. ':' .. tostring(value.range.start.line) .. ':' .. tostring(value.range.start.character) + .. ':' .. tostring(value.range['end'].line) .. ':' .. tostring(value.range['end'].character) + if dict[key] == nil then + dict[key] = i + else + local j = dict[key] + if not locations[j].definition then + del[#del] = i + else + del[#del] = j + end + end + end + for i = #del, 1, -1 do + table.remove(locations, del[i]) + end end -- log("num", num) -- log("bfnr", bufnr)