diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index b479b5596a8..f85f4b443de 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2910,6 +2910,11 @@ Actual: ${stringify(fullActual)}`); } private verifyDocumentHighlights(expectedRanges: Range[], fileNames: ReadonlyArray = [this.activeFile.fileName]) { + expectedRanges = ts.map(expectedRanges, r => { + r.fileName = ts.normalizePath(r.fileName); + return r; + }); + fileNames = ts.map(fileNames, ts.normalizePath); const documentHighlights = this.getDocumentHighlightsAtCurrentPosition(fileNames) || []; for (const dh of documentHighlights) { @@ -3219,7 +3224,7 @@ Actual: ${stringify(fullActual)}`); } } else if (ts.isString(indexOrName)) { - let name = indexOrName; + let name = ts.normalizePath(indexOrName); // names are stored in the compiler with this relative path, this allows people to use goTo.file on just the fileName name = name.indexOf("/") === -1 ? (this.basePath + "/" + name) : name; diff --git a/src/harness/virtualFileSystem.ts b/src/harness/virtualFileSystem.ts index 16267a092fc..698f99616ca 100644 --- a/src/harness/virtualFileSystem.ts +++ b/src/harness/virtualFileSystem.ts @@ -125,7 +125,7 @@ namespace Utils { addFile(path: string, content?: Harness.LanguageService.ScriptInfo) { const absolutePath = ts.normalizePath(ts.getNormalizedAbsolutePath(path, this.currentDirectory)); - const fileName = ts.getBaseFileName(path); + const fileName = ts.getBaseFileName(absolutePath); const directoryPath = ts.getDirectoryPath(absolutePath); const directory = this.addDirectory(directoryPath); return directory ? directory.addFile(fileName, content) : undefined; diff --git a/tests/cases/fourslash/documentHighlights_windowsPath.ts b/tests/cases/fourslash/documentHighlights_windowsPath.ts new file mode 100644 index 00000000000..594f175745b --- /dev/null +++ b/tests/cases/fourslash/documentHighlights_windowsPath.ts @@ -0,0 +1,7 @@ +/// + +//@Filename: C:\a\b\c.ts +////var /*1*/[|x|] = 1; + +const range = test.ranges()[0]; +verify.documentHighlightsOf(range, [range], { filesToSearch: [range.fileName] }); \ No newline at end of file