diff --git a/lua/jsonfly/parsers.lua b/lua/jsonfly/parsers.lua index eee1f5d..9536ff8 100644 --- a/lua/jsonfly/parsers.lua +++ b/lua/jsonfly/parsers.lua @@ -19,6 +19,12 @@ local PRIMITIVE_TYPES = { number = true, boolean = true, } +local CONTAINS_CHILDREN_TYPES = { + [2] = true, -- Module / Javascript Object + [8] = true, -- Field + [18] = true, -- Array + [19] = true, -- Object +} local M = {} @@ -91,7 +97,7 @@ end ---@return string|number|table|boolean|nil function M:parse_lsp_value(result) -- Object - if result.kind == 2 then + if CONTAINS_CHILDREN_TYPES[result.kind] then local value = {} for _, child in ipairs(result.children) do @@ -165,7 +171,7 @@ function M:get_entries_from_lsp_symbols(symbols) } 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) for jindex=1, #sub_keys do diff --git a/lua/telescope/_extensions/jsonfly.lua b/lua/telescope/_extensions/jsonfly.lua index 9be4c4b..089484b 100644 --- a/lua/telescope/_extensions/jsonfly.lua +++ b/lua/telescope/_extensions/jsonfly.lua @@ -56,7 +56,7 @@ local DEFAULT_CONFIG = { }, jump_behavior = "key_start", subkeys_display = "normal", - show_nested_child_preview = false, + show_nested_child_preview = true, backend = "lsp", use_cache = 500, commands = { @@ -196,17 +196,19 @@ return require("telescope").register_extension { if global_config.backend == "lsp" then local params = vim.lsp.util.make_position_params(xopts.winnr) - vim.lsp.buf_request( + vim.lsp.buf_request_all( current_buf, "textDocument/documentSymbol", params, - function(error, lsp_response) - if error then + function(response) + if response == nil or #response == 0 then run_lua_parser() return 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 cache:cache_buffer(current_buf, entries)