Skip to content

Conversation

@johnfav03
Copy link
Contributor

Fixes #1892

Fixed crash produced by nil parent in accessKind, then fixed incorrect behavior in findAllReferences.go and documentHighlights.go. The textRange from the reference wasn't being returned by getReferencedSymbolsForModule, and getSemanticHighlights unnecessarily checked the status of the reference's node.

@johnfav03 johnfav03 requested review from DanielRosenwasser, andrewbranch, Copilot and jakebailey and removed request for Copilot October 24, 2025 21:05
Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

Seems right, but do you have a test that can show this?

Comment on lines 2355 to +2358
parent := node.Parent
if parent == nil {
return AccessKindRead
}
Copy link
Member

Choose a reason for hiding this comment

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

Ah yes, Strada said:

function accessKind(node: Node): AccessKind {
    const { parent } = node;

    switch (parent?.kind) {

Love the ol "parent is never undefined except when it totally is"

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a comment

Choose a reason for hiding this comment

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

Test

Copilot AI review requested due to automatic review settings October 27, 2025 15:53
Copy link
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 PR fixes a crash and incorrect behavior in document highlighting for reference directives. The fix addresses issue #1892 where requesting highlights on a reference directive path would crash due to a nil parent in accessKind and fail to return proper highlight ranges.

Key changes:

  • Added nil check in accessKind to prevent crashes when processing reference directive nodes
  • Changed getReferencedSymbolsForModule to be a method on LanguageService to access LSP range creation utilities
  • Fixed reference entry creation for reference directives to return proper text ranges instead of node-based entries
  • Removed unnecessary node nil check in getSemanticDocumentHighlights that was preventing reference directive highlights

Reviewed Changes

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

Show a summary per file
File Description
internal/ast/ast.go Added nil parent guard in accessKind and fixed missing closing brace
internal/ls/findallreferences.go Changed getReferencedSymbolsForModule to instance method and fixed reference entry creation for directives
internal/ls/documenthighlights.go Removed unnecessary node nil check that blocked reference directive highlights
internal/fourslash/tests/documentHighlightReferenceDirective_test.go Added test case for document highlighting on reference directives
testdata/baselines/reference/fourslash/documentHighlights/documentHighlightReferenceDirective.baseline.jsonc Added baseline output for the new test

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

LGTM, ast package fix is sufficient to fix the crash but the other stuff appears to improve the output.

@johnfav03 johnfav03 added this pull request to the merge queue Oct 27, 2025
Merged via the queue into microsoft:main with commit f0ca632 Oct 27, 2025
22 checks passed
@johnfav03 johnfav03 deleted the document-highlights-fix branch October 27, 2025 19:29
github-merge-queue bot pushed a commit that referenced this pull request Oct 28, 2025
Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
Co-authored-by: John Favret <64748847+johnfav03@users.noreply.github.com>
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 crashes on type reference directive to @typescript-eslint/utils

5 participants