in server/src/jsonStore.ts [475:531]
private findTargets<T extends (DefinitionResult | DeclarationResult)>(uri: string, position: lsp.Position, edges: Map<Id, T>): lsp.Location | lsp.Location[] | undefined {
const ranges = this.findRangesFromPosition(this.toDatabase(uri), position);
if (ranges === undefined) {
return undefined;
}
const resolveTargets = (result: lsp.Location[], dedupLocations: Set<string>, targetResult: T): void => {
const ranges = this.item(targetResult);
if (ranges === undefined) {
return undefined;
}
for (const element of ranges) {
this.addLocation(result, element, dedupLocations);
}
};
const _findTargets = (result: lsp.Location[], dedupLocations: Set<string>, dedupMonikers: Set<string>, range: Range): void => {
const resultPath = this.getResultPath(range.id, edges);
if (resultPath.result === undefined) {
return undefined;
}
const mostSpecificMoniker = this.getMostSpecificMoniker(resultPath);
const monikers: Moniker[] = mostSpecificMoniker !== undefined ? [mostSpecificMoniker] : [];
resolveTargets(result, dedupLocations, resultPath.result.value);
for (const moniker of monikers) {
if (dedupMonikers.has(moniker.key)) {
continue;
}
dedupMonikers.add(moniker.key);
const matchingMonikers = this.indices.monikers.get(moniker.key);
if (matchingMonikers !== undefined) {
for (const matchingMoniker of matchingMonikers) {
const vertices = this.findVerticesForMoniker(matchingMoniker);
if (vertices !== undefined) {
for (const vertex of vertices) {
const resultPath = this.getResultPath(vertex.id, edges);
if (resultPath.result === undefined) {
continue;
}
resolveTargets(result, dedupLocations, resultPath.result.value);
}
}
}
}
}
};
const result: lsp.Location[] = [];
const dedupLocations: Set<string> = new Set();
const dedupMonikers: Set<string> = new Set();
for (const range of ranges) {
_findTargets(result, dedupLocations, dedupMonikers, range);
}
return result;
}