Repository navigation
fix(move): no-op when buffer has no treesitter parser (#883) - #903
Open
simonyang08 wants to merge 1 commit into
Open
simonyang08 wants to merge 1 commit into
simonyang08 wants to merge 1 commit into
Conversation
…r#883) Movement functions (goto_next_start/end, goto_previous_start/end, goto_next, goto_previous, and the repeatable wrappers) raised a Lua error on buffers without an attached treesitter parser: E5108: .../move.lua:86: attempt to perform arithmetic on local 'score' (a nil value) E5108: .../move.lua:142: attempt to compare two nil values Root cause: shared.find_best_range() returned an empty table ({}) when no parser was attached for the buffer. The empty table is truthy in Lua, so move.lua proceeded to call scoring_function({}) and filter_function({}) on it, dereferencing nil fields. Selection textobjects (select_textobject) already handled this case silently because best_range_at_point() returns nil when its input list is empty. Fix: have find_best_range() return nil (matching its annotated return type Range6?) instead of {} when the parser is missing, so the existing 'if current_range then' guard in move.lua correctly skips the iteration and goto_node() is invoked with nil (which it already handles as a no-op). Verified with scripts/repro_883.lua: - before fix: 9/10 entry points error - after fix: 10/10 entry points return silently - parser-present path unaffected: move.goto_next_start on a C buffer still jumps to the function definition row. Fixes nvim-treesitter#883 Signed-off-by: simonyang08 <ppt5928@gmail.com>
simonyang08
marked this pull request as ready for review
October 1, 2026 01:18
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.
Fixes #883.
Movement functions (
goto_next_start,goto_next_end,goto_previous_start,goto_previous_end,goto_next,goto_previous, and therepeatable_movewrappers) raised a Lua error on buffers without an attached treesitter parser:Root cause
shared.find_best_range()returned an empty table ({}) when no parser was attached. An empty table is truthy in Lua, somove.luaproceeded to callscoring_function({})andfilter_function({}), dereferencingnilfields.select_textobjectwas already silent becausebest_range_at_point()returnsnilwhen its input list is empty — the asymmetry is purely on thefind_best_rangeside.Fix
Make
find_best_range()returnnil(matching its annotated return typeRange6?) instead of{}when the parser is missing. The existingif current_range thenguard inmove.luathen correctly skips the iteration, andgoto_node(nil, …)already no-ops in that case.Test
New
tests/move/no_parser_spec.lua: renders a scratch buffer with no filetype/parser and asserts every movement entry point is a silent no-op. The spec fails onmain(9 of the calls raise the two error shapes from the issue) and passes with the fix.Note: on buffers whose filetype maps to a registered but uninstalled parser,
vim.treesitter.get_parseritself can still throw — that is core behavior outside this fix.stylua clean; full local suite not run end-to-end (the bundled
nvim-treesitterinstall script fails in this environment, unrelated to this change) — CI will exercise it.