Skip to content

fix(view): handle nil parser from get_parser in get_context - #55

Open
SAY-5 wants to merge 1 commit into
folke:mainfrom
SAY-5:fix-no-parser-crash
Open

SAY-5 wants to merge 1 commit into
folke:mainfrom
SAY-5:fix-no-parser-crash

Conversation

@SAY-5

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

Copy link
Copy Markdown

Description

vim.treesitter.get_parser returns nil (not an error) on Neovim 0.12 for buffers without a parser, so pcall(vim.treesitter.get_parser, buf) returns true and the subsequent get_node call dereferences a nil parser in for_each_tree. Capture the second return value and gate on parser ~= nil so .txt and other parser-less filetypes no-op instead of crashing.

Related Issue(s)

vim.treesitter.get_parser now returns nil (not an error) for buffers
without a parser, so pcall returns true and the subsequent
get_node call dereferences a nil parser in for_each_tree. Capture the
return value and gate on parser ~= nil so .txt and other parser-less
filetypes no-op instead of crashing.

Fixes folke#54

Signed-off-by: Sai Asish <say.apm35@gmail.com>
@github-actions github-actions Bot added the size/s Small PR (<10 lines changed) label May 12, 2026
@mdedonno1337

Copy link
Copy Markdown

hi. any update ?

@SAY-5

SAY-5 commented Jun 20, 2026

Copy link
Copy Markdown
Author

Yeah, still relevant. The patch captures the parser returned by get_parser and gates on it being non-nil, so buffers without a parser (txt and similar) fall through to the line-based path instead of crashing in get_node. It's still based on current main and mergeable, ready whenever you get a chance to look.

Chiarandini added a commit to Chiarandini/NoetherVim that referenced this pull request Nov 6, 2026
twilight.nvim asks for a buffer's parser expecting an error when there
is none, but Neovim 0.12 returns nil, so zen mode crashed in any buffer
without a treesitter parser. twilight has had no commit since October
2025 and the fix (folke/twilight.nvim#55) is unmerged. Snacks.zen and
Snacks.dim do the same with what NoetherVim already ships, falling back
to indent scopes where there is no parser. <leader>z and :ZenMode work
as before; zen-mode.nvim and twilight.nvim go.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s Small PR (<10 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: pcall(treesitter.get_parser) returns 'true' when parser is nil

2 participants