Skip to content

Commit 48f98bd

Browse files
Merge pull request #23452 from uniqueiniquity/normalizeDocumentHighlightsPaths
Normalize document highlights paths
2 parents f6510bd + 12f6e52 commit 48f98bd

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/harness/fourslash.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,6 +2910,7 @@ Actual: ${stringify(fullActual)}`);
29102910
}
29112911

29122912
private verifyDocumentHighlights(expectedRanges: Range[], fileNames: ReadonlyArray<string> = [this.activeFile.fileName]) {
2913+
fileNames = ts.map(fileNames, ts.normalizePath);
29132914
const documentHighlights = this.getDocumentHighlightsAtCurrentPosition(fileNames) || [];
29142915

29152916
for (const dh of documentHighlights) {
@@ -2919,7 +2920,7 @@ Actual: ${stringify(fullActual)}`);
29192920
}
29202921

29212922
for (const fileName of fileNames) {
2922-
const expectedRangesInFile = expectedRanges.filter(r => r.fileName === fileName);
2923+
const expectedRangesInFile = expectedRanges.filter(r => ts.normalizePath(r.fileName) === fileName);
29232924
const highlights = ts.find(documentHighlights, dh => dh.fileName === fileName);
29242925
const spansInFile = highlights ? highlights.highlightSpans.sort((s1, s2) => s1.textSpan.start - s2.textSpan.start) : [];
29252926

@@ -3219,14 +3220,14 @@ Actual: ${stringify(fullActual)}`);
32193220
}
32203221
}
32213222
else if (ts.isString(indexOrName)) {
3222-
let name = indexOrName;
3223+
let name = ts.normalizePath(indexOrName);
32233224

32243225
// names are stored in the compiler with this relative path, this allows people to use goTo.file on just the fileName
32253226
name = name.indexOf("/") === -1 ? (this.basePath + "/" + name) : name;
32263227

32273228
const availableNames: string[] = [];
32283229
const result = ts.forEach(this.testData.files, file => {
3229-
const fn = file.fileName;
3230+
const fn = ts.normalizePath(file.fileName);
32303231
if (fn) {
32313232
if (fn === name) {
32323233
return file;

src/harness/virtualFileSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ namespace Utils {
125125

126126
addFile(path: string, content?: Harness.LanguageService.ScriptInfo) {
127127
const absolutePath = ts.normalizePath(ts.getNormalizedAbsolutePath(path, this.currentDirectory));
128-
const fileName = ts.getBaseFileName(path);
128+
const fileName = ts.getBaseFileName(absolutePath);
129129
const directoryPath = ts.getDirectoryPath(absolutePath);
130130
const directory = this.addDirectory(directoryPath);
131131
return directory ? directory.addFile(fileName, content) : undefined;

src/services/services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ namespace ts {
16731673
}
16741674

16751675
function getDocumentHighlights(fileName: string, position: number, filesToSearch: ReadonlyArray<string>): DocumentHighlights[] {
1676-
Debug.assert(contains(filesToSearch, fileName));
1676+
Debug.assert(filesToSearch.some(f => normalizePath(f) === fileName));
16771677
synchronizeHostData();
16781678
const sourceFilesToSearch = map(filesToSearch, f => Debug.assertDefined(program.getSourceFile(f)));
16791679
const sourceFile = getValidSourceFile(fileName);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//@Filename: C:\a\b\c.ts
4+
////var /*1*/[|x|] = 1;
5+
6+
const range = test.ranges()[0];
7+
verify.documentHighlightsOf(range, [range], { filesToSearch: [range.fileName] });

0 commit comments

Comments
 (0)