Fix the issue with file being included in the referencing project on … · WebReflection/TypeScript@ab4be8d · GitHub
Skip to content

Commit ab4be8d

Browse files
committed
Fix the issue with file being included in the referencing project on rename when it wasnt included earlier
Fixes microsoft#28307
1 parent 16ea9af commit ab4be8d

3 files changed

Lines changed: 140 additions & 73 deletions

File tree

src/compiler/sourcemapDecoder.ts

Lines changed: 1 addition & 1 deletion

src/services/sourcemaps.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ namespace ts {
2323
let sourcemappedFileCache: SourceFileLikeCache;
2424
return { tryGetOriginalLocation, tryGetGeneratedLocation, toLineColumnOffset, clearCache };
2525

26+
function toPath(fileName: string) {
27+
return ts.toPath(fileName, currentDirectory, getCanonicalFileName);
28+
}
29+
2630
function scanForSourcemapURL(fileName: string) {
27-
const mappedFile = sourcemappedFileCache.get(toPath(fileName, currentDirectory, getCanonicalFileName));
31+
const mappedFile = sourcemappedFileCache.get(toPath(fileName));
2832
if (!mappedFile) {
2933
return;
3034
}
@@ -88,7 +92,7 @@ namespace ts {
8892
}
8993
possibleMapLocations.push(fileName + ".map");
9094
for (const location of possibleMapLocations) {
91-
const mapPath = toPath(location, getDirectoryPath(fileName), getCanonicalFileName);
95+
const mapPath = ts.toPath(location, getDirectoryPath(fileName), getCanonicalFileName);
9296
if (host.fileExists(mapPath)) {
9397
return convertDocumentToSourceMapper(file, host.readFile(mapPath)!, mapPath); // TODO: GH#18217
9498
}
@@ -120,12 +124,16 @@ namespace ts {
120124
}
121125

122126
function getFile(fileName: string): SourceFileLike | undefined {
123-
return getProgram().getSourceFile(fileName) || sourcemappedFileCache.get(toPath(fileName, currentDirectory, getCanonicalFileName));
127+
const path = toPath(fileName);
128+
const file = getProgram().getSourceFileByPath(path);
129+
if (file && file.resolvedPath === path) {
130+
return file;
131+
}
132+
return sourcemappedFileCache.get(path);
124133
}
125134

126135
function toLineColumnOffset(fileName: string, position: number): LineAndCharacter {
127-
const path = toPath(fileName, currentDirectory, getCanonicalFileName);
128-
const file = getProgram().getSourceFile(path) || sourcemappedFileCache.get(path)!; // TODO: GH#18217
136+
const file = getFile(fileName)!; // TODO: GH#18217
129137
return file.getLineAndCharacterOfPosition(position);
130138
}
131139

src/testRunner/unittests/tsserverProjectSystem.ts

Lines changed: 126 additions & 67 deletions

0 commit comments

Comments
 (0)