Skip to content

Fix document highlights crashes on missing tokens/nodes#2672

Merged
DanielRosenwasser merged 9 commits intomainfrom
fixDocHighlights
Feb 4, 2026
Merged

Fix document highlights crashes on missing tokens/nodes#2672
DanielRosenwasser merged 9 commits intomainfrom
fixDocHighlights

Conversation

@DanielRosenwasser
Copy link
Copy Markdown
Member

Fixes #2670.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a crash in document highlights when encountering incomplete try-catch-finally statements and malformed if-else statements. The crash occurred when the language server attempted to find catch/finally keywords that didn't exist or when incorrectly casting else statements to if statements.

Changes:

  • Fixed nil pointer dereference in getTryCatchFinallyOccurrences by adding nil checks for catch and finally tokens
  • Fixed unsafe type cast in getIfElseKeywords by checking if the else statement is actually an if statement before casting
  • Added comprehensive tests for broken/incomplete control flow structures

Reviewed changes

Copilot reviewed 40 out of 40 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/ls/documenthighlights.go Fixed nil checks in getTryCatchFinallyOccurrences and unsafe cast in getIfElseKeywords
internal/fourslash/tests/gen/*.go Added test cases for broken try-catch-finally, if-else, switch-case, return, and other control flow structures
testdata/baselines/reference/fourslash/documentHighlights/*.baseline.jsonc Generated baseline outputs for new test cases
internal/fourslash/_scripts/failingTests.txt Updated to reflect new failing test
internal/fourslash/_scripts/crashingTests.txt Updated to reflect new crashing test
internal/fourslash/_scripts/convertFourslash.mts Added support for test.markers() in baseline document highlights

@DanielRosenwasser DanielRosenwasser added this pull request to the merge queue Feb 4, 2026

var keywords []*ast.Node
token := lsutil.GetFirstToken(node, sourceFile)
if token.Kind == ast.KindTryKeyword {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a porting oopsie because the original pushKeywordIf dealt with nil and the Go version got rid of it and those occurrences weren't handling nil. I see we have other occurrences of pushKeywordIf in Strada. Do we need to also go and fix other occurrences other than those ones in this PR?

Merged via the queue into main with commit 5d64e31 Feb 4, 2026
20 checks passed
@DanielRosenwasser DanielRosenwasser deleted the fixDocHighlights branch February 4, 2026 18:32
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.

Document highlights crash when missing catch and finally clauses

4 participants