Skip to content
Prev Previous commit
Next Next commit
Move de-duping upstream to fix Full output
  • Loading branch information
amcasey committed May 17, 2022
commit 70032036f6f5e289f56643fb94c13e44cc968e0d
17 changes: 8 additions & 9 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ namespace ts.server {
// of each definition and merging references from all the projects where they appear.

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

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

for (const ref of referencedSymbol.references) {
if (!contains(symbolToAddTo.references, ref, documentSpansEqual) && !getMappedLocationForProject(documentSpanLocation(ref), project)) {
if (!seenRefs.has(ref) && !getMappedLocationForProject(documentSpanLocation(ref), project)) {
seenRefs.add(ref);
symbolToAddTo.references.push(ref);
}
}
Expand Down Expand Up @@ -1803,14 +1808,8 @@ namespace ts.server {
const nameSpan = nameInfo && nameInfo.textSpan;
const symbolStartOffset = nameSpan ? scriptInfo.positionToLineOffset(nameSpan.start).offset : 0;
const symbolName = nameSpan ? scriptInfo.getSnapshot().getText(nameSpan.start, textSpanEnd(nameSpan)) : "";
const refs: protocol.ReferencesResponseItem[] = [];
const seen = createDocumentSpanSet();
references.forEach(referencedSymbol => {
referencedSymbol.references.forEach(entry => {
if (tryAddToSet(seen, entry)) {
refs.push(referenceEntryToReferencesResponseItem(this.projectService, entry));
}
});
const refs: readonly protocol.ReferencesResponseItem[] = flatMap(references, referencedSymbol => {
return referencedSymbol.references.map(entry => referenceEntryToReferencesResponseItem(this.projectService, entry));
});
return { refs, symbolName, symbolStartOffset, symbolDisplayString };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@
// export function FC() {}
// }
//
// interface [|I|][|I|] {
// interface [|I|] {
// FC();
// }
//
// const ic: [|I|][|I|] = { FC() {} };
// const ic: [|I|] = { FC() {} };

// === /a/index.ts ===
// namespace NS {
Expand Down Expand Up @@ -230,61 +230,6 @@
"isDefinition": false
}
]
},
{
"definition": {
"containerKind": "",
"containerName": "",
"fileName": "/c/index.ts",
"kind": "interface",
"name": "interface I",
"textSpan": {
"start": 56,
"length": 1
},
"displayParts": [
{
"text": "interface",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "I",
"kind": "interfaceName"
}
],
"contextSpan": {
"start": 46,
"length": 25
}
},
"references": [
{
"textSpan": {
"start": 56,
"length": 1
},
"fileName": "/c/index.ts",
"contextSpan": {
"start": 46,
"length": 25
},
"isWriteAccess": true,
"isDefinition": true
},
{
"textSpan": {
"start": 83,
"length": 1
},
"fileName": "/c/index.ts",
"isWriteAccess": false,
"isDefinition": false
}
]
}
]

Expand Down Expand Up @@ -533,11 +478,11 @@
// export function FC() {}
// }
//
// interface [|I|][|I|] {
// interface [|I|] {
// FC();
// }
//
// const ic: [|I|][|I|] = { FC() {} };
// const ic: [|I|] = { FC() {} };

// === /a/index.ts ===
// namespace NS {
Expand Down Expand Up @@ -655,61 +600,6 @@
"isDefinition": false
}
]
},
{
"definition": {
"containerKind": "",
"containerName": "",
"fileName": "/c/index.ts",
"kind": "interface",
"name": "interface I",
"textSpan": {
"start": 56,
"length": 1
},
"displayParts": [
{
"text": "interface",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "I",
"kind": "interfaceName"
}
],
"contextSpan": {
"start": 46,
"length": 25
}
},
"references": [
{
"textSpan": {
"start": 56,
"length": 1
},
"fileName": "/c/index.ts",
"contextSpan": {
"start": 46,
"length": 25
},
"isWriteAccess": true,
"isDefinition": true
},
{
"textSpan": {
"start": 83,
"length": 1
},
"fileName": "/c/index.ts",
"isWriteAccess": false,
"isDefinition": false
}
]
}
]

Expand Down Expand Up @@ -945,11 +835,11 @@
// export function FC() {}
// }
//
// interface /*FIND ALL REFS*/[|I|]/*FIND ALL REFS*/[|I|] {
// interface /*FIND ALL REFS*/[|I|] {
// FC();
// }
//
// const ic: [|I|][|I|] = { FC() {} };
// const ic: [|I|] = { FC() {} };

// === /b/index.ts ===
// namespace NS {
Expand Down Expand Up @@ -1088,28 +978,6 @@
"isWriteAccess": false,
"isDefinition": false
},
{
"textSpan": {
"start": 56,
"length": 1
},
"fileName": "/c/index.ts",
"contextSpan": {
"start": 46,
"length": 25
},
"isWriteAccess": true,
"isDefinition": true
},
{
"textSpan": {
"start": 83,
"length": 1
},
"fileName": "/c/index.ts",
"isWriteAccess": false,
"isDefinition": false
},
{
"textSpan": {
"start": 75,
Expand Down