Skip to content

Commit 430e24f

Browse files
committed
Move de-duping upstream to fix Full output
1 parent 48ebb19 commit 430e24f

File tree

2 files changed

+14
-147
lines changed

2 files changed

+14
-147
lines changed

src/server/session.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,11 @@ namespace ts.server {
429429
// of each definition and merging references from all the projects where they appear.
430430

431431
const results: ReferencedSymbol[] = [];
432+
const seenRefs = createDocumentSpanSet(); // It doesn't make sense to have a reference in two definition lists, so we de-dup globally
432433

434+
// TODO: We might end up with a more logical allocation of refs to defs if we pre-sorted the defs by descending ref-count.
435+
// Otherwise, it just ends up attached to the first corresponding def we happen to process. The others may or may not be
436+
// dropped later when we check for defs with ref-count 0.
433437
perProjectResults.forEach((projectResults, project) => {
434438
for (const referencedSymbol of projectResults) {
435439
const mappedDefinitionFile = getMappedLocationForProject(documentSpanLocation(referencedSymbol.definition), project);
@@ -449,7 +453,8 @@ namespace ts.server {
449453
}
450454

451455
for (const ref of referencedSymbol.references) {
452-
if (!contains(symbolToAddTo.references, ref, documentSpansEqual) && !getMappedLocationForProject(documentSpanLocation(ref), project)) {
456+
if (!seenRefs.has(ref) && !getMappedLocationForProject(documentSpanLocation(ref), project)) {
457+
seenRefs.add(ref);
453458
symbolToAddTo.references.push(ref);
454459
}
455460
}
@@ -1649,14 +1654,8 @@ namespace ts.server {
16491654
const nameSpan = nameInfo && nameInfo.textSpan;
16501655
const symbolStartOffset = nameSpan ? scriptInfo.positionToLineOffset(nameSpan.start).offset : 0;
16511656
const symbolName = nameSpan ? scriptInfo.getSnapshot().getText(nameSpan.start, textSpanEnd(nameSpan)) : "";
1652-
const refs: protocol.ReferencesResponseItem[] = [];
1653-
const seen = createDocumentSpanSet();
1654-
references.forEach(referencedSymbol => {
1655-
referencedSymbol.references.forEach(entry => {
1656-
if (tryAddToSet(seen, entry)) {
1657-
refs.push(referenceEntryToReferencesResponseItem(this.projectService, entry));
1658-
}
1659-
});
1657+
const refs: readonly protocol.ReferencesResponseItem[] = flatMap(references, referencedSymbol => {
1658+
return referencedSymbol.references.map(entry => referenceEntryToReferencesResponseItem(this.projectService, entry));
16601659
});
16611660
return { refs, symbolName, symbolStartOffset, symbolDisplayString };
16621661
}

tests/baselines/reference/isDefinitionAcrossGlobalProjects.baseline.jsonc

Lines changed: 6 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@
108108
// export function FC() {}
109109
// }
110110
//
111-
// interface [|I|][|I|] {
111+
// interface [|I|] {
112112
// FC();
113113
// }
114114
//
115-
// const ic: [|I|][|I|] = { FC() {} };
115+
// const ic: [|I|] = { FC() {} };
116116

117117
// === /a/index.ts ===
118118
// namespace NS {
@@ -230,61 +230,6 @@
230230
"isDefinition": false
231231
}
232232
]
233-
},
234-
{
235-
"definition": {
236-
"containerKind": "",
237-
"containerName": "",
238-
"fileName": "/c/index.ts",
239-
"kind": "interface",
240-
"name": "interface I",
241-
"textSpan": {
242-
"start": 56,
243-
"length": 1
244-
},
245-
"displayParts": [
246-
{
247-
"text": "interface",
248-
"kind": "keyword"
249-
},
250-
{
251-
"text": " ",
252-
"kind": "space"
253-
},
254-
{
255-
"text": "I",
256-
"kind": "interfaceName"
257-
}
258-
],
259-
"contextSpan": {
260-
"start": 46,
261-
"length": 25
262-
}
263-
},
264-
"references": [
265-
{
266-
"textSpan": {
267-
"start": 56,
268-
"length": 1
269-
},
270-
"fileName": "/c/index.ts",
271-
"contextSpan": {
272-
"start": 46,
273-
"length": 25
274-
},
275-
"isWriteAccess": true,
276-
"isDefinition": true
277-
},
278-
{
279-
"textSpan": {
280-
"start": 83,
281-
"length": 1
282-
},
283-
"fileName": "/c/index.ts",
284-
"isWriteAccess": false,
285-
"isDefinition": false
286-
}
287-
]
288233
}
289234
]
290235

@@ -533,11 +478,11 @@
533478
// export function FC() {}
534479
// }
535480
//
536-
// interface [|I|][|I|] {
481+
// interface [|I|] {
537482
// FC();
538483
// }
539484
//
540-
// const ic: [|I|][|I|] = { FC() {} };
485+
// const ic: [|I|] = { FC() {} };
541486

542487
// === /a/index.ts ===
543488
// namespace NS {
@@ -655,61 +600,6 @@
655600
"isDefinition": false
656601
}
657602
]
658-
},
659-
{
660-
"definition": {
661-
"containerKind": "",
662-
"containerName": "",
663-
"fileName": "/c/index.ts",
664-
"kind": "interface",
665-
"name": "interface I",
666-
"textSpan": {
667-
"start": 56,
668-
"length": 1
669-
},
670-
"displayParts": [
671-
{
672-
"text": "interface",
673-
"kind": "keyword"
674-
},
675-
{
676-
"text": " ",
677-
"kind": "space"
678-
},
679-
{
680-
"text": "I",
681-
"kind": "interfaceName"
682-
}
683-
],
684-
"contextSpan": {
685-
"start": 46,
686-
"length": 25
687-
}
688-
},
689-
"references": [
690-
{
691-
"textSpan": {
692-
"start": 56,
693-
"length": 1
694-
},
695-
"fileName": "/c/index.ts",
696-
"contextSpan": {
697-
"start": 46,
698-
"length": 25
699-
},
700-
"isWriteAccess": true,
701-
"isDefinition": true
702-
},
703-
{
704-
"textSpan": {
705-
"start": 83,
706-
"length": 1
707-
},
708-
"fileName": "/c/index.ts",
709-
"isWriteAccess": false,
710-
"isDefinition": false
711-
}
712-
]
713603
}
714604
]
715605

@@ -945,11 +835,11 @@
945835
// export function FC() {}
946836
// }
947837
//
948-
// interface /*FIND ALL REFS*/[|I|]/*FIND ALL REFS*/[|I|] {
838+
// interface /*FIND ALL REFS*/[|I|] {
949839
// FC();
950840
// }
951841
//
952-
// const ic: [|I|][|I|] = { FC() {} };
842+
// const ic: [|I|] = { FC() {} };
953843

954844
// === /b/index.ts ===
955845
// namespace NS {
@@ -1088,28 +978,6 @@
1088978
"isWriteAccess": false,
1089979
"isDefinition": false
1090980
},
1091-
{
1092-
"textSpan": {
1093-
"start": 56,
1094-
"length": 1
1095-
},
1096-
"fileName": "/c/index.ts",
1097-
"contextSpan": {
1098-
"start": 46,
1099-
"length": 25
1100-
},
1101-
"isWriteAccess": true,
1102-
"isDefinition": true
1103-
},
1104-
{
1105-
"textSpan": {
1106-
"start": 83,
1107-
"length": 1
1108-
},
1109-
"fileName": "/c/index.ts",
1110-
"isWriteAccess": false,
1111-
"isDefinition": false
1112-
},
1113981
{
1114982
"textSpan": {
1115983
"start": 75,

0 commit comments

Comments
 (0)