fix: parse() call for Neovim 0.10+ API#674
Draft
eric-chapdelaine wants to merge 3 commits into
Draft
Conversation
f73fd40 to
e776576
Compare
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.
e776576 to
537f336
Compare
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.
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.
romgrk
reviewed
May 19, 2026
Comment on lines
+238
to
+242
| 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) |
Collaborator
There was a problem hiding this comment.
So pcall() is just to fix some test environment error? Feels wrong to use it :/
Author
There was a problem hiding this comment.
I agree! I didn't mean to set this PR as ready to review just yet. Let me play around with this more and I will message you when it's ready for review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Details
In Neovim 0.10+, LanguageTree:parse() requires an array of ranges instead of a single Range4 table. Added a version check (
vim.version().minor >= 10) to use:{ range }array for Neovim 0.10+rangesingle value for Neovim 0.9This ensures full backwards compatibility with both versions.