Skip to content

Commit

Permalink
fix: Improve parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed May 25, 2024
1 parent ce0e163 commit 31be718
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 8 additions & 2 deletions lua/jsonfly/parsers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions lua/telescope/_extensions/jsonfly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 31be718

Please sign in to comment.