From 03723b59cb48ecc92262fda25b2f211c0c550bcd Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sun, 14 Apr 2024 10:33:49 +0200 Subject: [PATCH] fix: Fix LSP keys behavior --- lua/telescope/_extensions/jsonfly.lua | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lua/telescope/_extensions/jsonfly.lua b/lua/telescope/_extensions/jsonfly.lua index bac8ac8..aa923ac 100644 --- a/lua/telescope/_extensions/jsonfly.lua +++ b/lua/telescope/_extensions/jsonfly.lua @@ -42,8 +42,6 @@ local entry_display = require "telescope.pickers.entry_display" local function get_entries_from_lua_json(t) local keys = {} - --@type k string - --@type raw_value InputEntry for k, raw_value in pairs(t) do ---@type Entry local entry = { @@ -133,6 +131,22 @@ local function get_entries_from_lsp_symbols(symbols) for _, symbol in ipairs(symbols) do local key = symbol.name + ---@type Entry + local entry = { + key = key, + value = parse_lsp_value(symbol), + position = { + line_number = symbol.range.start.line + 2, + key_start = symbol.range.start.character + 2, + -- The LSP doesn't return the start of the value, so we'll just assume it's 3 characters after the key + -- We assume a default JSON file like: + -- `"my_key": "my_value"` + -- Since we get the end of the key, we can just add 4 to get the start of the value + value_start = symbol.selectionRange["end"].character + 4 + } + } + table.insert(keys, entry) + if symbol.kind == 2 then local sub_keys = get_entries_from_lsp_symbols(symbol.children) @@ -147,18 +161,6 @@ local function get_entries_from_lsp_symbols(symbols) table.insert(keys, entry) end end - - ---@type Entry - local entry = { - key = key, - value = parse_lsp_value(symbol), - position = { - line_number = symbol.range["end"].line, - key_start = symbol.range.start.character, - value_start = symbol.selectionRange.start.character, - } - } - table.insert(keys, entry) end return keys @@ -284,8 +286,6 @@ return require"telescope".register_extension { local _, raw_depth = entry.key:gsub("%.", ".") local depth = (raw_depth or 0) + 1 - print(vim.inspect(entry)) - return make_entry.set_default_entry_mt({ value = current_buf, ordinal = entry.key,