summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authortheprimeagain <the.primeagen@gmail.com>2026-02-04 10:24:24 -0700
committertheprimeagain <the.primeagen@gmail.com>2026-02-04 10:24:24 -0700
commit1a0363ee23d8aff7162dc96ce2987dcb3cab42f7 (patch)
tree9ca7e4a9878079ed83571bd2751a45807ad0315e /lua
parent4b7c22a488f3e637b6d4c09dbc59865956aa396a (diff)
downloada4-1a0363ee23d8aff7162dc96ce2987dcb3cab42f7.tar.xz
a4-1a0363ee23d8aff7162dc96ce2987dcb3cab42f7.zip
... did we just go viral
Diffstat (limited to 'lua')
-rw-r--r--lua/99/editor/lsp.lua21
-rw-r--r--lua/99/editor/treesitter.lua61
-rw-r--r--lua/99/test/fill_in_function.typescript_spec.lua2
3 files changed, 77 insertions, 7 deletions
diff --git a/lua/99/editor/lsp.lua b/lua/99/editor/lsp.lua
index 0214669..8ef0751 100644
--- a/lua/99/editor/lsp.lua
+++ b/lua/99/editor/lsp.lua
@@ -211,11 +211,28 @@ local function get_lsp_document_symbols(bufnr, cb)
)
end
+--- @class _99.lsp.ExportPosition
+--- @field name string
+--- @field line number
+--- @field col number
+
+--- @class _99.lsp.ExportMember
+--- @field name string
+--- @field line number
+--- @field col number
+--- @field kind number|nil
+
+--- @class _99.lsp.ExportMetadata
+--- @field kind number|nil
+--- @field members _99.lsp.ExportMember[]|nil
+
+--- @alias _99.lsp.ExportMeta table<string, _99.lsp.ExportMetadata>
+
--- Extracts export keys and metadata from LSP document symbols.
---
--- @param symbols table|nil LSP document symbols
---- @return { name: string, line: number, col: number }[] export_keys
---- @return table<string, { kind: number|nil, members: { name: string, line: number, col: number, kind: number|nil }[]|nil }>
+--- @return _99.lsp.ExportPosition[] export_keys
+--- @return _99.lsp.ExportMeta export_meta
local function document_symbols_to_exports(symbols)
local export_keys = {}
local export_meta = {}
diff --git a/lua/99/editor/treesitter.lua b/lua/99/editor/treesitter.lua
index b1c7f3d..d5efbac 100644
--- a/lua/99/editor/treesitter.lua
+++ b/lua/99/editor/treesitter.lua
@@ -23,13 +23,66 @@ local fn_call_query = "99-fn-call"
---@param lang string
local function tree_root(buffer, lang)
-- Load the parser and the query.
+ print(
+ "[treesitter] Attempting to get parser for buffer="
+ .. buffer
+ .. ", lang="
+ .. tostring(lang)
+ )
+ Logger:debug("tree_root called", "buffer", buffer, "lang", lang, "id", "69")
+
local ok, parser = pcall(vim.treesitter.get_parser, buffer, lang)
if not ok then
+ print("[treesitter] ERROR: Failed to get parser - " .. tostring(parser))
+ Logger:debug("Failed to get parser", "error", tostring(parser), "id", "69")
+ return nil
+ end
+
+ print("[treesitter] Parser obtained successfully, type=" .. type(parser))
+ Logger:debug("Parser obtained", "parser_type", type(parser), "id", "69")
+
+ local parse_ok, trees = pcall(function()
+ return parser:parse()
+ end)
+ if not parse_ok then
+ print("[treesitter] ERROR: Failed to parse - " .. tostring(trees))
+ Logger:debug("Failed to parse", "error", tostring(trees), "id", "69")
+ return nil
+ end
+
+ print(
+ "[treesitter] Parse completed, trees count=" .. (trees and #trees or "nil")
+ )
+ Logger:debug(
+ "Parse completed",
+ "trees_count",
+ trees and #trees or 0,
+ "id",
+ "69"
+ )
+
+ if not trees or #trees == 0 then
+ print("[treesitter] ERROR: No trees returned from parse")
+ Logger:debug("No trees returned", "id", "69")
+ return nil
+ end
+
+ local tree = trees[1]
+ print("[treesitter] Getting root from tree[1], tree=" .. tostring(tree))
+ Logger:debug("Got tree[1]", "tree_type", type(tree), "id", "69")
+
+ local root_ok, root = pcall(function()
+ return tree:root()
+ end)
+ if not root_ok then
+ print("[treesitter] ERROR: Failed to get root - " .. tostring(root))
+ Logger:debug("Failed to get root", "error", tostring(root), "id", "69")
return nil
end
- local tree = parser:parse()[1]
- return tree:root()
+ print("[treesitter] Root obtained successfully, type=" .. type(root))
+ Logger:debug("Root obtained", "root_type", type(root), "id", "69")
+ return root
end
--- @param context _99.RequestContext
@@ -147,10 +200,10 @@ function M.containing_function(context, cursor)
local lang = context.file_type
local logger = context and context.logger:set_area("treesitter") or Logger
- logger:error("loading lang", "buffer", buffer, "lang", lang)
+ logger:debug("loading lang", "buffer", buffer, "lang", lang)
local root = tree_root(buffer, lang)
if not root then
- logger:debug("LSP: could not find tree root")
+ logger:debug("could not find tree root")
return nil
end
diff --git a/lua/99/test/fill_in_function.typescript_spec.lua b/lua/99/test/fill_in_function.typescript_spec.lua
index 0586a9c..83708e8 100644
--- a/lua/99/test/fill_in_function.typescript_spec.lua
+++ b/lua/99/test/fill_in_function.typescript_spec.lua
@@ -10,7 +10,7 @@ describe("typescript", function()
"",
"const foo = function() {}",
}
- local p, buffer = test_utils.fif_setup(ts_content, 2, 12, "typescript")
+ local p, buffer = test_utils.fif_setup(ts_content, 2, 16, "typescript")
local state = _99.__get_state()
_99.fill_in_function()