Skip to content

Conversation

ahejlsberg
Copy link
Member

Panic occurs when opening a file with cursor positioned in a commented out section at the beginning of the file.

Copy link
Contributor

@Copilot 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

Fixes a panic in the LSP document-highlight feature that occurs when a cursor is positioned in a commented out section at the beginning of a file. The fix adds a missing nil check to prevent dereferencing a nil pointer.

  • Adds nil check for resolvedRef before accessing its fields

Comment on lines +619 to 621
if resolvedRef == nil || resolvedRef.file == nil {
return nil
}
Copy link

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

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

The nil check for resolvedRef should be performed before accessing any of its fields. Consider splitting this into two separate checks for better readability and to avoid potential short-circuit evaluation issues: first check if resolvedRef == nil and return early, then check if resolvedRef.file == nil.

Suggested change
if resolvedRef == nil || resolvedRef.file == nil {
return nil
}
if resolvedRef == nil {
return nil
}
if resolvedRef.file == nil {
return nil
}

Copilot uses AI. Check for mistakes.

@ahejlsberg ahejlsberg added this pull request to the merge queue Sep 28, 2025
Merged via the queue into main with commit 458dd3b Sep 28, 2025
22 checks passed
@ahejlsberg ahejlsberg deleted the fix-document-highlight-panic branch September 28, 2025 21:00
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.

2 participants