Repository navigation
fix(view): guard treesitter parser against missing/invalid parsers - #56
Open
thenomadlad wants to merge 1 commit into
Open
thenomadlad wants to merge 1 commit into
thenomadlad wants to merge 1 commit into
Conversation
…d parsers Wraps vim.treesitter.get_parser in a single pcall in get_context, which acts as the sole gate for the treesitter path. get_node and expand now receive the parser as an argument, keeping them as pure tree-traversal functions with no error handling of their own. Falls back to line-based context when treesitter is disabled or no valid parser exists for the buffer. Fixes folke#54. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
thenomadlad
force-pushed
the
fix/treesitter-parser-crash
branch
from
May 15, 2026 05:56
a681a55 to
24e8007
Compare
|
hi. any update ? |
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 #54.
Problem
Two crash paths in
get_node:vim.treesitter.get_parser(buf)was called without error handling — throws for filetypes with no registered parser, crashing the whole dimming update.root:descendant_for_rangecan return nil when the cursor position falls outside the tree's range (e.g. empty or truncated lines), and:parent()was called on it immediately without a nil check.Solution
get_context: acquires the parser once withpcalland checks both the config flag and parser validity before entering the treesitter path. Falls back to line-based context if either fails.get_node(parser, buf, line): receives the parser as an argument — pure tree traversal, no error handling, no config checks. Guards against nil return fromdescendant_for_rangebefore dereferencing.expand(parser, buf, ...): threads the parser through toget_node, same logic.The safety boundary is unambiguous: one pcall in
get_contextgates everything, andget_nodehandles the nil node case internally.🤖 Generated with Claude Code