Skip to content

Add language support #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -130,6 +130,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 @@ -138,10 +142,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
1 change: 1 addition & 0 deletions lua/telescope/_extensions/jsonfly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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