From 537f3362f2976f412d5cc55ecfa63f470ebf5836 Mon Sep 17 00:00:00 2001 From: Eric Chapdelaine Date: Sun, 17 May 2026 21:40:32 -0400 Subject: [PATCH 1/3] fix: parse() call for Neovim 0.10+ API In Neovim 0.10+, LanguageTree:parse() requires an array of ranges instead of a single Range4 table. Wrapping 'range' in braces fixes the 'attempt to call method range (a nil value)' error when moving the cursor in buffers with treesitter parsing. Added explicit type annotation to satisfy lua-language-server. --- lua/treesitter-context/context.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/treesitter-context/context.lua b/lua/treesitter-context/context.lua index 1b370180..302c2833 100644 --- a/lua/treesitter-context/context.lua +++ b/lua/treesitter-context/context.lua @@ -235,8 +235,9 @@ local function get_parent_langtrees(bufnr, range) return {} end + local range_arr = { range } --- @type Range4[] --- @diagnostic disable-next-line:redundant-parameter added in 0.11 - root_tree:parse(range, function(...) end) + root_tree:parse(range_arr, function(...) end) local ret = { root_tree } while true do From f5c3809a0ec3d3bbc0f15d0d7150e08672486ff5 Mon Sep 17 00:00:00 2001 From: Eric Chapdelaine Date: Sun, 17 May 2026 21:49:51 -0400 Subject: [PATCH 2/3] fix: add version check for parse() API compatibility Neovim 0.9 and earlier don't accept an array for parse(), only a single range. Add a version check to use array syntax only for 0.10+ while keeping backwards compatibility with 0.9. --- lua/treesitter-context/context.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/treesitter-context/context.lua b/lua/treesitter-context/context.lua index 302c2833..d6c8d774 100644 --- a/lua/treesitter-context/context.lua +++ b/lua/treesitter-context/context.lua @@ -235,9 +235,9 @@ local function get_parent_langtrees(bufnr, range) return {} end - local range_arr = { range } --- @type Range4[] + local parse_ranges = vim.version().minor >= 10 and { range } or range --- @diagnostic disable-next-line:redundant-parameter added in 0.11 - root_tree:parse(range_arr, function(...) end) + root_tree:parse(parse_ranges, function(...) end) local ret = { root_tree } while true do From 441d8ed0437f34079f2c5c909f16e6efbf7b722d Mon Sep 17 00:00:00 2001 From: Eric Chapdelaine Date: Sun, 17 May 2026 21:57:03 -0400 Subject: [PATCH 3/3] fix: use pcall to handle parse() API differences Try Neovim 0.10+ array syntax first, fall back to single range for older versions. This avoids version checks that may not work reliably across different test environments. --- lua/treesitter-context/context.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lua/treesitter-context/context.lua b/lua/treesitter-context/context.lua index d6c8d774..3eb01f71 100644 --- a/lua/treesitter-context/context.lua +++ b/lua/treesitter-context/context.lua @@ -235,9 +235,11 @@ local function get_parent_langtrees(bufnr, range) return {} end - local parse_ranges = vim.version().minor >= 10 and { range } or range - --- @diagnostic disable-next-line:redundant-parameter added in 0.11 - root_tree:parse(parse_ranges, function(...) end) + local function try_parse(tree, r, cb) + local ok = pcall(function() tree:parse({ r }, cb) end) + if not ok then tree:parse(r, cb) end + end + try_parse(root_tree, range, function(...) end) local ret = { root_tree } while true do