Skip to content

Restore go-to-definition for triple-slash lib references - #64088

Open
Daniel Rosenwasser (DanielRosenwasser) with Copilot wants to merge 4 commits into
mainfrom
copilot/go-to-definition-fix
Open

Restore go-to-definition for triple-slash lib references#64088
Daniel Rosenwasser (DanielRosenwasser) with Copilot wants to merge 4 commits into
mainfrom
copilot/go-to-definition-fix

Conversation

Copilot AI commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Description

Go-to-definition stopped resolving positions within /// <reference lib="..." /> directives in TypeScript 7.

Changes

  • Resolve triple-slash references before the source-file fallback.
  • Index resolved libraries by canonical filename, including bundled and replacement libraries.
  • Add fourslash coverage for multiple positions in an es2025 reference.
/// <reference lib="es2025" />

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix go-to-definition for reference lib directives Restore go-to-definition for triple-slash lib references Aug 28, 2026
Comment thread tsc/internal/compiler/program.go Outdated
Comment on lines +2094 to +2095
if path, ok := p.libFilesByName[name]; ok {
return p.filesByPath[path]

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.

I don't get it - if we have a source file, then we have a path right? As far as I understand, we don't need libFilesByName, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You’re right. p.libFiles already maps each resolved source-file path to its LibFile, so the lookup now matches LibFile.Name there and uses that path to retrieve the source file. Removed libFilesByName in c7a702e.

t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: /src/app.ts
/// <reference lib="/*start*/e/*middle*/s202/*end*/5" />`

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.

Suggested change
/// <reference lib="/*start*/e/*middle*/s202/*end*/5" />`
/// <reference lib="/*start*/es/*middle*/2025/*end*/" />`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the test markers to /*start*/es/*middle*/2025/*end*/ and refreshed its baseline in c7a702e.

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
}
if sourceFile, ok := p.filesByPath[tspath.Path(path)]; ok {
return sourceFile
for path, libFile := range p.libFiles {

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.

I guess this was a bug - these were not actual paths.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Restores go-to-definition for triple-slash library references in the language service.

Changes:

  • Resolves references before the SourceFile fallback.
  • Locates libraries through canonical metadata.
  • Adds fourslash coverage and baselines.
Show a summary per file
File Description
tsc/internal/ls/definition.go Reorders reference resolution.
tsc/internal/compiler/program.go Resolves canonical library paths.
tsc/internal/fourslash/tests/goToDefinitionTypeReferenceDirective_test.go Adds library-reference coverage.
tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinitionLibReferenceDirective.baseline.jsonc Adds the new expected baseline.
tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinitionSourceUnit.baseline.jsonc Updates path-reference output.
tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinitionTypeReferenceDirective.baseline.jsonc Updates type-reference output.

Review details

  • Files reviewed: 6/6 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines 54 to +60
originSelectionRange, _ := l.createLspRangeFromNode(node, file)
if reference != nil && reference.file != nil {
return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, []*ast.Node{}, reference, spanmap.FeatureDefinition)
}
if node.Kind == ast.KindSourceFile {
return lsproto.LocationOrLocationsOrDefinitionLinksOrNull{}
}

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.

Copilot address

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated triple-slash definition links to use the matched FileReference range for the origin selection and refreshed the affected baselines in 81167b9.

@jakebailey Jake Bailey (jakebailey) left a comment

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.

I also found this bug separately while working on a fun Path refactor.

@DanielRosenwasser

Copy link
Copy Markdown
Member

Copilot I actually think the origin selection range should be the text - I dunno, check what strada did

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>

Copilot AI commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Copilot I actually think the origin selection range should be the text - I dunno, check what strada did

Verified: FileReference.TextRange is populated from the parser's pragma argument range, which is only the unquoted reference text. The committed change already uses that range; the updated baselines show [|es2025|], [|lib|], and [|b.ts|] rather than the enclosing directive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Go-to-definition does not work on /// <reference lib="..." /> directives

4 participants