Skip to content

Commit eb804a9

Browse files
committed
getSemanticDocumentHighlights: don't fail...
...when missing `program.redirectTargetsMap` info. This assertion fails in the added test case -- looks like there is no entry in `program.redirectTargetsMap` when it comes from a file that is no in the project. So in this case don't follow the (missing) info, and instead drop the highlight. Fixes #33722.
1 parent 42b0e3c commit eb804a9

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/services/documentHighlights.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ namespace ts {
3232
const referenceEntries = FindAllReferences.getReferenceEntriesForNode(position, node, program, sourceFilesToSearch, cancellationToken, /*options*/ undefined, sourceFilesSet);
3333
if (!referenceEntries) return undefined;
3434
const map = arrayToMultiMap(referenceEntries.map(FindAllReferences.toHighlightSpan), e => e.fileName, e => e.span);
35-
return arrayFrom(map.entries(), ([fileName, highlightSpans]) => {
35+
return mapDefined(arrayFrom(map.entries()), ([fileName, highlightSpans]) => {
3636
if (!sourceFilesSet.has(fileName)) {
37-
Debug.assert(program.redirectTargetsMap.has(fileName));
37+
if (!program.redirectTargetsMap.has(fileName)) {
38+
return undefined;
39+
}
3840
const redirectTarget = program.getSourceFile(fileName);
3941
const redirect = find(sourceFilesToSearch, f => !!f.redirectInfo && f.redirectInfo.redirectTarget === redirectTarget)!;
4042
fileName = redirect.fileName;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: /y.ts
4+
////class Foo {
5+
//// private foo() {}
6+
////}
7+
////
8+
////const f = () => new Foo();
9+
////export default f;
10+
11+
// @Filename: /x.ts
12+
////import y from "./y";
13+
////
14+
////y().[|foo|]();
15+
16+
const [r] = test.ranges();
17+
verify.documentHighlightsOf(r, [], { filesToSearch: ["/x.ts"] });

0 commit comments

Comments
 (0)