Skip to content
Draft
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 {
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")
}
7 changes: 3 additions & 4 deletions tsc/internal/ls/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ 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 {
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,12 +11,18 @@


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

// === /a.ts ===
// //MyFile Comments
// //more comments
// /// <reference path="somePath.ts" />
// /// <reference path="b/*GOTO DEF*/.ts" />
//
// class clsInOverload {
// [|class clsInOverload {
// static fnOverload();
// --- (line: 8) skipped ---
// static fnOverload(foo: string);
// static fnOverload(foo: any) { }
// }
// |]
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*/"/>
// $.x;
// [|$.x;|]