Skip to content

fix(shared): return nil when no parser in find_best_range#886

Open
SAY-5 wants to merge 1 commit into
nvim-treesitter:mainfrom
SAY-5:fix-move-no-parser
Open

fix(shared): return nil when no parser in find_best_range#886
SAY-5 wants to merge 1 commit into
nvim-treesitter:mainfrom
SAY-5:fix-move-no-parser

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 12, 2026

Empty tables are truthy in Lua, so the if current_range then guard in move.lua did not short-circuit when find_best_range hit the no-parser branch. The empty table then reached scoring_function and crashed with attempt to perform arithmetic on local 'score' (a nil value) on buffers without a parser (e.g. :e test.txt).

Return nil to match the documented Range6? signature and bring movement functions in line with the select textobjects no-op behavior.

Fixes #883

An empty table is truthy in Lua, so callers that guard with
'if range then' did not short-circuit when find_best_range hit
the no-parser branch. In move.lua the empty table reached
scoring_function and crashed with 'attempt to perform arithmetic
on local score (a nil value)' on buffers without a parser.
Return nil to match the documented Range6? signature.

Fixes nvim-treesitter#883

Signed-off-by: Sai Asish <say.apm35@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

textobjects.move errors when no Treesitter parser is available (should no-op like select)

1 participant