Skip to content

Commit 23eb591

Browse files
authored
Lookup files by resolved Path and not by fileName in sourcemapDecoder when querying program (microsoft#25908)
* Check if the file returned by the program actually refers to the same file as we intend * Simplify
1 parent f6d3ac9 commit 23eb591

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

src/compiler/sourcemapDecoder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ namespace ts.sourcemaps {
9898

9999
function getSourceFileLike(fileName: string, location: string): SourceFileLike | undefined {
100100
// Lookup file in program, if provided
101-
const file = program && program.getSourceFile(fileName);
101+
const path = toPath(fileName, location, host.getCanonicalFileName);
102+
const file = program && program.getSourceFile(path);
102103
if (!file) {
103104
// Otherwise check the cache (which may hit disk)
104-
const path = toPath(fileName, location, host.getCanonicalFileName);
105105
return fallbackCache.get(path);
106106
}
107107
return file;

src/harness/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ namespace FourSlash {
709709

710710
ts.zipWith(endMarkers, definitions, (endMarker, definition, i) => {
711711
const marker = this.getMarkerByName(endMarker);
712-
if (marker.fileName !== definition.fileName || marker.position !== definition.textSpan.start) {
712+
if (ts.comparePaths(marker.fileName, definition.fileName, /*ignoreCase*/ true) !== ts.Comparison.EqualTo || marker.position !== definition.textSpan.start) {
713713
this.raiseError(`${testName} failed for definition ${endMarker} (${i}): expected ${marker.fileName} at ${marker.position}, got ${definition.fileName} at ${definition.textSpan.start}`);
714714
}
715715
});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/// <reference path="../fourslash.ts" />
2+
// @Filename: BaseClass/Source.d.ts
3+
////declare class Control {
4+
//// constructor();
5+
//// /** this is a super var */
6+
//// myVar: boolean | 'yeah';
7+
////}
8+
//////# sourceMappingURL=Source.d.ts.map
9+
// @Filename: BaseClass/Source.d.ts.map
10+
////{"version":3,"file":"Source.d.ts","sourceRoot":"","sources":["Source.ts"],"names":[],"mappings":"AAAA,cAAM,OAAO;;IAIT,0BAA0B;IACnB,KAAK,EAAE,OAAO,GAAG,MAAM,CAAQ;CACzC"}
11+
// @Filename: BaseClass/Source.ts
12+
////class /*2*/Control{
13+
//// constructor(){
14+
//// return;
15+
//// }
16+
//// /** this is a super var */
17+
//// public /*4*/myVar: boolean | 'yeah' = true;
18+
////}
19+
// @Filename: tsbase.json
20+
////{
21+
//// "$schema": "http://json.schemastore.org/tsconfig",
22+
//// "compileOnSave": true,
23+
//// "compilerOptions": {
24+
//// "sourceMap": true,
25+
//// "declaration": true,
26+
//// "declarationMap": true
27+
//// }
28+
//// }
29+
// @Filename: buttonClass/tsconfig.json
30+
////{
31+
//// "extends": "../tsbase.json",
32+
//// "compilerOptions": {
33+
//// "outFile": "Source.js"
34+
//// },
35+
//// "files": [
36+
//// "Source.ts"
37+
//// ],
38+
//// "include": [
39+
//// "../BaseClass/Source.d.ts"
40+
//// ]
41+
//// }
42+
// @Filename: buttonClass/Source.ts
43+
////// I cannot F12 navigate to Control
44+
////// vvvvvvv
45+
////class Button extends [|/*1*/Control|] {
46+
//// public myFunction() {
47+
//// // I cannot F12 navigate to myVar
48+
//// // vvvvv
49+
//// if (typeof this.[|/*3*/myVar|] === 'boolean') {
50+
//// this.myVar;
51+
//// } else {
52+
//// this.myVar.toLocaleUpperCase();
53+
//// }
54+
//// }
55+
////}
56+
57+
verify.goToDefinition("1", "2");
58+
verify.goToDefinition("3", "4");

0 commit comments

Comments
 (0)