Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions tsc/internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -2087,12 +2087,14 @@ func (p *Program) ExplainFiles(w io.Writer, locale locale.Locale) {
}

func (p *Program) GetLibFileFromReference(ref *ast.FileReference) *ast.SourceFile {
path, ok := tsoptions.GetLibFileName(ref.FileName)
name, ok := tsoptions.GetLibFileName(ref.FileName)
if !ok {
return nil
}
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.

if libFile.Name == name {
return p.filesByPath[path]
}
}
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ func TestGoToDefinitionTypeReferenceDirective(t *testing.T) {
defer done()
f.VerifyBaselineGoToDefinition(t, true, "1")
}

func TestGoToDefinitionLibReferenceDirective(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: /src/app.ts
/// <reference lib="/*start*/es/*middle*/2025/*end*/" />`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifyBaselineGoToDefinition(t, true, "start", "middle", "end")
}
10 changes: 6 additions & 4 deletions tsc/internal/ls/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ func (l *LanguageService) provideDefinitionAtPosition(ctx context.Context, progr
node := astnav.GetTouchingPropertyName(file, pos)
reference := getReferenceAtPosition(file, pos, program)

if node.Kind == ast.KindSourceFile {
return lsproto.LocationOrLocationsOrDefinitionLinksOrNull{}
}

originSelectionRange, _ := l.createLspRangeFromNode(node, file)
if reference != nil && reference.file != nil {
if node.Kind == ast.KindSourceFile {
originSelectionRange, _ = l.createLspRangeFromBounds(reference.reference.Pos(), reference.reference.End(), file)
}
return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, []*ast.Node{}, reference, spanmap.FeatureDefinition)
}
if node.Kind == ast.KindSourceFile {
return lsproto.LocationOrLocationsOrDefinitionLinksOrNull{}
}

c, done := program.GetTypeCheckerForFile(ctx, file)
defer done()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// === goToDefinition ===
// === bundled:///libs/lib.es2025.d.ts ===
// [||]/*! *****************************************************************************
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// --- (line: --) skipped ---
//

// === /src/app.ts ===
// /// <reference lib="/*GOTO DEF*/[|es2025|]" />



// === goToDefinition ===
// === bundled:///libs/lib.es2025.d.ts ===
// [||]/*! *****************************************************************************
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// --- (line: --) skipped ---
//

// === /src/app.ts ===
// /// <reference lib="[|es/*GOTO DEF*/2025|]" />



// === goToDefinition ===
// === bundled:///libs/lib.es2025.d.ts ===
// [||]/*! *****************************************************************************
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// --- (line: --) skipped ---
//

// === /src/app.ts ===
// /// <reference lib="[|es2025|]/*GOTO DEF*/" />
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@


// === goToDefinition ===
// === /b.ts ===
// [||]

// === /a.ts ===
// //MyFile Comments
// //more comments
// /// <reference path="somePath.ts" />
// /// <reference path="b/*GOTO DEF*/.ts" />
// /// <reference path="[|b/*GOTO DEF*/.ts|]" />
//
// class clsInOverload {
// static fnOverload();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// === goToDefinition ===
// === /src/types/lib/index.d.ts ===
// [||]declare let $: {x: number};

// === /src/app.ts ===
// /// <reference types="lib/*GOTO DEF*/"/>
// /// <reference types="[|lib|]/*GOTO DEF*/"/>
// $.x;