From c3350797f9304f530491472f57fef4c98fb6a036 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sun, 12 May 2024 19:35:34 +0200 Subject: [PATCH] debug --- lua/jsonfly/languages.lua | 28 +++++++++++++++++++++++++++ lua/jsonfly/parsers.lua | 8 ++++---- lua/telescope/_extensions/jsonfly.lua | 11 +++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 lua/jsonfly/languages.lua diff --git a/lua/jsonfly/languages.lua b/lua/jsonfly/languages.lua new file mode 100644 index 0000000..f9e7931 --- /dev/null +++ b/lua/jsonfly/languages.lua @@ -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; diff --git a/lua/jsonfly/parsers.lua b/lua/jsonfly/parsers.lua index eee1f5d..beee8ae 100644 --- a/lua/jsonfly/parsers.lua +++ b/lua/jsonfly/parsers.lua @@ -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 @@ -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 diff --git a/lua/telescope/_extensions/jsonfly.lua b/lua/telescope/_extensions/jsonfly.lua index ed59e01..6cd2173 100644 --- a/lua/telescope/_extensions/jsonfly.lua +++ b/lua/telescope/_extensions/jsonfly.lua @@ -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" @@ -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