diff --git a/src/services/services.ts b/src/services/services.ts index 93145e01223..d2e9900d936 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1565,7 +1565,7 @@ namespace ts { const normalizedFileName = normalizePath(fileName); Debug.assert(filesToSearch.some(f => normalizePath(f) === normalizedFileName)); synchronizeHostData(); - const sourceFilesToSearch = filesToSearch.map(getValidSourceFile); + const sourceFilesToSearch = mapDefined(filesToSearch, fileName => program.getSourceFile(fileName)); const sourceFile = getValidSourceFile(fileName); return DocumentHighlights.getDocumentHighlights(program, cancellationToken, sourceFile, position, sourceFilesToSearch); } diff --git a/tests/cases/fourslash/documentHighlights_moduleImport_filesToSearchWithInvalidFile.ts b/tests/cases/fourslash/documentHighlights_moduleImport_filesToSearchWithInvalidFile.ts new file mode 100644 index 00000000000..d72d6868b96 --- /dev/null +++ b/tests/cases/fourslash/documentHighlights_moduleImport_filesToSearchWithInvalidFile.ts @@ -0,0 +1,17 @@ +/// + +// @Filename: /node_modules/@types/foo/index.d.ts +////export const x: number; + +// @Filename: /a.ts +////import * as foo from "foo"; +////foo.[|x|]; + +// @Filename: /b.ts +////import { [|x|] } from "foo"; + +// @Filename: /c.ts +////import { x } from "foo"; + +const [r0, r1] = test.ranges(); +verify.rangesAreDocumentHighlights(test.ranges(), { filesToSearch: ["/a.ts", "/b.ts", "/unknown.ts"] });