Skip to content

fix: prevent treesitter context panic on incomplete SQL#706

Closed
psteinroe wants to merge 1 commit intomainfrom
fix/parsing-error
Closed

fix: prevent treesitter context panic on incomplete SQL#706
psteinroe wants to merge 1 commit intomainfrom
fix/parsing-error

Conversation

@psteinroe
Copy link
Copy Markdown
Collaborator

@psteinroe psteinroe commented Mar 3, 2026

Closes #704

Root cause: ScopeTracker::register() in ancestors.rs assumes the first node it encounters is always a scope boundary (statement, ERROR, or program). When tree-sitter parses malformed SQL, nodes like function_arguments, :=, keyword_begin, etc. can appear as the first traversed node, leaving self.scopes empty and hitting an unwrap_or_else(panic!).

Fix:

  • Changed the scope creation condition to also create a fallback scope when self.scopes is empty. This gracefully degrades (completions/hover return nothing useful instead of crashing).
  • Added regression test that iterates all cursor positions in an incomplete function body to cover all node kinds from the issue.

@juleswritescode
Copy link
Copy Markdown
Collaborator

juleswritescode commented Mar 6, 2026

Hmm, soooo the issue is actually that scope-boundaries are missing (block, transactions etc.).
The point of the panic was to alert us of missing boundaries, so I'd like to keep it there and maybe nudge the user to give us a good issue.

etc. can appear as the first traversed node

that's not true — the issue is that a parent boundary was missing.

to also create a fallback scope

is that outdated? I'm only seeing an .is_empty() check?

@juleswritescode
Copy link
Copy Markdown
Collaborator

Added an alternative solution here: #709

@psteinroe psteinroe closed this Mar 6, 2026
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.

bug: language server closes on treesitter CST parsing errors - unhandled node kind: function_arguments

2 participants