Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed May 12, 2024
1 parent acd899c commit c335079
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
28 changes: 28 additions & 0 deletions lua/jsonfly/languages.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
local M = {};

---Only keep entries that are a parent of the child that is at the given position.
---This is useful to remove all entries that are not relevant to the current cursor position for example.
---Modifies the given `symbol` in place.
---@param symbol Symbol
---@param position Position
function M:filter_lsp_symbol_by_position(symbol, position)
if type(symbol.children) == "table" and #symbol.children > 0 then
for index=1, #symbol.children do
local child = symbol.children[index]

print("child", vim.inspect(child));
self:filter_lsp_symbol_by_position(child, position)
end
end

local r = symbol.selectionRange
-- Let's just do a simple check
if r.start.line >= position.line and r["end"].line <= position.line then
return true
end

return false
end


return M;
8 changes: 4 additions & 4 deletions lua/jsonfly/parsers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ function M:parse_lsp_value(result)
end


---@class Range
---@field start Position
---@field ["end"] Position
--
---@class Symbol
---@field name string
---@field kind number 2 = Object, 16 = Number, 15 = String, 18 = Array, 13 = Null, 17 = Boolean
Expand All @@ -132,10 +136,6 @@ end
---@field detail string
---@field children Symbol[]
--
---@class Range
---@field start Position
---@field ["end"] Position
--
---@class Position
---@field line number
---@field character number
Expand Down
11 changes: 11 additions & 0 deletions lua/telescope/_extensions/jsonfly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ local parsers = require"jsonfly.parsers"
local utils = require"jsonfly.utils"
local cache = require"jsonfly.cache"
local insert = require"jsonfly.insert"
local languages = require"jsonfly.languages"

local json = require"jsonfly.json"
local finders = require "telescope.finders"
Expand Down Expand Up @@ -196,6 +197,16 @@ return require"telescope".register_extension {
"textDocument/documentSymbol",
params,
function(error, lsp_response)
print(vim.inspect(lsp_response))

languages:filter_lsp_symbol_by_position(
lsp_response[1],
params.position
)

print(vim.inspect(lsp_response))


if error then
run_lua_parser()
return
Expand Down

0 comments on commit c335079

Please sign in to comment.