summaryrefslogtreecommitdiff
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
parent4b7c22a488f3e637b6d4c09dbc59865956aa396a (diff)
downloada4-1a0363ee23d8aff7162dc96ce2987dcb3cab42f7.tar.xz
a4-1a0363ee23d8aff7162dc96ce2987dcb3cab42f7.zip
... did we just go viral
-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
-rw-r--r--queries/typescript/99-function.scm2
-rw-r--r--scratch/test.ts30
-rw-r--r--scripts/tests/minimal.vim20
6 files changed, 103 insertions, 33 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()
diff --git a/queries/typescript/99-function.scm b/queries/typescript/99-function.scm
index 4e2656f..1f240aa 100644
--- a/queries/typescript/99-function.scm
+++ b/queries/typescript/99-function.scm
@@ -1,6 +1,6 @@
(function_declaration) @context.function
-(function) @context.function
(arrow_function) @context.function
+(function_expression) @context.function
(method_definition) @context.function
(generator_function) @context.function
(generator_function_declaration) @context.function
diff --git a/scratch/test.ts b/scratch/test.ts
index a6399f9..c7a13c6 100644
--- a/scratch/test.ts
+++ b/scratch/test.ts
@@ -1,23 +1,19 @@
-
function fizz_buzz_classic() {
- for (let i = 1; i <= 100; i++) {
- if (i % 15 === 0) {
- console.log("FizzBuzz");
- } else if (i % 3 === 0) {
- console.log("Fizz");
- } else if (i % 5 === 0) {
- console.log("Buzz");
- } else {
- console.log(i);
- }
+ for (let i = 1; i <= 100; i++) {
+ if (i % 15 === 0) {
+ console.log("FizzBuzz");
+ } else if (i % 3 === 0) {
+ console.log("Fizz");
+ } else if (i % 5 === 0) {
+ console.log("Buzz");
+ } else {
+ console.log(i);
}
+ }
}
-const foo2 = () => {
-}
-const foo = function() {
-}
-
+const foo2 = () => {};
+const foo = function () {};
function display_text(
canvas: HTMLCanvasElement,
@@ -25,7 +21,7 @@ function display_text(
x: number,
y: number,
): void {
- // test
+ // test
}
function test_again() {}
diff --git a/scripts/tests/minimal.vim b/scripts/tests/minimal.vim
index b1e80d6..d6dcf39 100644
--- a/scripts/tests/minimal.vim
+++ b/scripts/tests/minimal.vim
@@ -1,4 +1,8 @@
" covers all package managers i am willing to cover
+" PRIORITY: lazy.nvim paths FIRST (prepend to ensure priority)
+set rtp^=~/.local/share/nvim/lazy/nvim-treesitter
+set rtp^=~/.local/share/nvim/lazy/plenary.nvim
+" Additional paths (append)
set rtp+=.
set rtp+=../plenary.nvim
set rtp+=../nvim-treesitter
@@ -8,8 +12,6 @@ set rtp+=~/.local/share/nvim/site/pack/packer/start/plenary.nvim
set rtp+=~/.local/share/nvim/site/pack/packer/start/nvim-treesitter
set rtp+=~/.local/share/lunarvim/site/pack/packer/start/plenary.nvim
set rtp+=~/.local/share/lunarvim/site/pack/packer/start/nvim-treesitter
-set rtp+=~/.local/share/nvim/lazy/plenary.nvim
-set rtp+=~/.local/share/nvim/lazy/nvim-treesitter
set autoindent
set tabstop=4
@@ -21,12 +23,9 @@ runtime! plugin/plenary.vim
runtime! plugin/nvim-treesitter.lua
lua <<EOF
-vim.opt.rtp:append(vim.fn.stdpath('data') .. '/site')
-
--- Always setup nvim-treesitter so it knows where to find parsers
-local install_dir = vim.fn.stdpath('data') .. '/site'
+-- Always setup nvim-treesitter
local ts = require('nvim-treesitter')
-ts.setup({ install_dir = install_dir })
+ts.setup()
-- parsers to attempt to install (for user convenience)
local all_parsers = {
@@ -40,10 +39,15 @@ local required_parsers = { 'lua', 'typescript' }
local function missing_parsers(parsers)
local missing = {}
local buf = vim.api.nvim_create_buf(false, true)
+ print('[minimal.vim] Checking for missing parsers...')
for _, lang in ipairs(parsers) do
- local ok = pcall(vim.treesitter.get_parser, buf, lang)
+ print('[minimal.vim] Checking parser for: ' .. lang)
+ local ok, err = pcall(vim.treesitter.get_parser, buf, lang)
if not ok then
+ print('[minimal.vim] Parser NOT found for ' .. lang .. ': ' .. tostring(err))
table.insert(missing, lang)
+ else
+ print('[minimal.vim] Parser FOUND for ' .. lang)
end
end
vim.api.nvim_buf_delete(buf, { force = true })