Filter and Sort Symbols according to my needs
This commit is contained in:
@@ -27,9 +27,79 @@ end
|
|||||||
local function parse_result(result, depth, hierarchy, parent, bufnr)
|
local function parse_result(result, depth, hierarchy, parent, bufnr)
|
||||||
local ret = {}
|
local ret = {}
|
||||||
|
|
||||||
|
-- LEIGH MOORE
|
||||||
|
-- Begin filter and Sort Symbols
|
||||||
|
local lspKind = {
|
||||||
|
[5] = 0, -- 'Class'
|
||||||
|
[7] = 1, -- 'Property'
|
||||||
|
[9] = 2, -- 'Constructor'
|
||||||
|
[6] = 3, -- 'Method'
|
||||||
|
[1] = 999, -- 'File'
|
||||||
|
[2] = 999, -- 'Module'
|
||||||
|
[3] = 999, -- 'Namespace'
|
||||||
|
[4] = 999, -- 'Package'
|
||||||
|
[8] = 999, -- 'Field'
|
||||||
|
[10] = 999, -- 'Enum'
|
||||||
|
[11] = 999, -- 'Interface'
|
||||||
|
[12] = 999, -- 'Function'
|
||||||
|
[13] = 999, -- 'Variable'
|
||||||
|
[14] = 999, -- 'Constant'
|
||||||
|
[15] = 999, -- 'String'
|
||||||
|
[16] = 999, -- 'Number'
|
||||||
|
[17] = 999, -- 'Boolean'
|
||||||
|
[18] = 999, -- 'Array'
|
||||||
|
[19] = 999, -- 'Object'
|
||||||
|
[20] = 999, -- 'Key'
|
||||||
|
[21] = 999, -- 'Null'
|
||||||
|
[22] = 999, -- 'EnumMember'
|
||||||
|
[23] = 999, -- 'Struct'
|
||||||
|
[24] = 999, -- 'Event'
|
||||||
|
[25] = 999, -- 'Operator'
|
||||||
|
[26] = 999, -- 'TypeParameter'
|
||||||
|
[27] = 999, -- 'Component'
|
||||||
|
[28] = 999, -- 'Fragment'
|
||||||
|
|
||||||
|
-- ccls
|
||||||
|
[252] = 999, -- 'TypeAlias'
|
||||||
|
[253] = 999, -- 'Parameter'
|
||||||
|
[254] = 999, -- 'StaticMethod'
|
||||||
|
[255] = 999, -- 'Macro'
|
||||||
|
}
|
||||||
|
|
||||||
|
local function filter_array(arr, predicate)
|
||||||
|
local result = {}
|
||||||
|
for _, value in ipairs(arr) do
|
||||||
|
-- vim.print(vim.inspect(value))
|
||||||
|
if predicate(value) then
|
||||||
|
table.insert(result, value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
result = filter_array(result, function(value)
|
||||||
|
return value.kind ~= 12 and value.name:match(' callback') == nil
|
||||||
|
end)
|
||||||
|
|
||||||
|
table.sort(result, function(a, b)
|
||||||
|
a.kind = norm_kind(a.kind)
|
||||||
|
b.kind = norm_kind(b.kind)
|
||||||
|
if lspKind[a.kind] < lspKind[b.kind] then
|
||||||
|
return true
|
||||||
|
elseif lspKind[a.kind] > lspKind[b.kind] then
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return a.name < b.name
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
-- End filter and Sort Symbols
|
||||||
|
|
||||||
|
local kinds = {}
|
||||||
|
|
||||||
for index, value in pairs(result) do
|
for index, value in pairs(result) do
|
||||||
-- FIXME: If a parent was excluded, all children will not be considered
|
-- FIXME: If a parent was excluded, all children will not be considered
|
||||||
value.kind = norm_kind(value.kind)
|
value.kind = norm_kind(value.kind)
|
||||||
|
kinds[value.kind] = true;
|
||||||
if cfg.should_include_symbol(symbols.kinds[value.kind], bufnr) then
|
if cfg.should_include_symbol(symbols.kinds[value.kind], bufnr) then
|
||||||
-- the hierarchy is basically a table of booleans which
|
-- the hierarchy is basically a table of booleans which
|
||||||
-- tells whether the parent was the last in its group or
|
-- tells whether the parent was the last in its group or
|
||||||
@@ -76,6 +146,8 @@ local function parse_result(result, depth, hierarchy, parent, bufnr)
|
|||||||
node.children = children
|
node.children = children
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
vim.print("KINDS")
|
||||||
|
vim.print(vim.inspect(kinds))
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user