fix: Improve parser

This commit is contained in:
Myzel394 2024-05-26 00:29:17 +02:00
parent ce0e163b8f
commit 31be7184ff
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
2 changed files with 15 additions and 7 deletions

View File

@ -19,6 +19,12 @@ local PRIMITIVE_TYPES = {
number = true, number = true,
boolean = true, boolean = true,
} }
local CONTAINS_CHILDREN_TYPES = {
[2] = true, -- Module / Javascript Object
[8] = true, -- Field
[18] = true, -- Array
[19] = true, -- Object
}
local M = {} local M = {}
@ -91,7 +97,7 @@ end
---@return string|number|table|boolean|nil ---@return string|number|table|boolean|nil
function M:parse_lsp_value(result) function M:parse_lsp_value(result)
-- Object -- Object
if result.kind == 2 then if CONTAINS_CHILDREN_TYPES[result.kind] then
local value = {} local value = {}
for _, child in ipairs(result.children) do for _, child in ipairs(result.children) do
@ -165,7 +171,7 @@ function M:get_entries_from_lsp_symbols(symbols)
} }
keys[#keys + 1] = entry keys[#keys + 1] = entry
if symbol.kind == 2 or symbol.kind == 18 then if CONTAINS_CHILDREN_TYPES[symbol.kind] then
local sub_keys = M:get_entries_from_lsp_symbols(symbol.children) local sub_keys = M:get_entries_from_lsp_symbols(symbol.children)
for jindex=1, #sub_keys do for jindex=1, #sub_keys do

View File

@ -56,7 +56,7 @@ local DEFAULT_CONFIG = {
}, },
jump_behavior = "key_start", jump_behavior = "key_start",
subkeys_display = "normal", subkeys_display = "normal",
show_nested_child_preview = false, show_nested_child_preview = true,
backend = "lsp", backend = "lsp",
use_cache = 500, use_cache = 500,
commands = { commands = {
@ -196,17 +196,19 @@ return require("telescope").register_extension {
if global_config.backend == "lsp" then if global_config.backend == "lsp" then
local params = vim.lsp.util.make_position_params(xopts.winnr) local params = vim.lsp.util.make_position_params(xopts.winnr)
vim.lsp.buf_request( vim.lsp.buf_request_all(
current_buf, current_buf,
"textDocument/documentSymbol", "textDocument/documentSymbol",
params, params,
function(error, lsp_response) function(response)
if error then if response == nil or #response == 0 then
run_lua_parser() run_lua_parser()
return return
end end
local entries = parsers:get_entries_from_lsp_symbols(lsp_response) local result = response[1].result
local entries = parsers:get_entries_from_lsp_symbols(result)
if allow_cache then if allow_cache then
cache:cache_buffer(current_buf, entries) cache:cache_buffer(current_buf, entries)