Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let bestMatch: SymbolInformation | undefined = undefined;
let bestRange: Range | undefined = undefined;
for (const candidate of symbols) {
const candidateRange = candidate.location.range;
if (utils.containsRange(candidateRange, reference.range)) {
// as opposed to default, find the topmost (earliest) symbol
if (!bestMatch || utils.startsAfter(bestRange!, candidateRange)) {
bestMatch = candidate;
bestRange = candidateRange;
}
}
}
if (bestMatch) {
// filter references that are in fact definitions
const nameLocation = await this.getSymbolNameLocation(bestMatch, context);
if (!nameLocation || utils.isSame(nameLocation, reference)) {
return undefined;
}
}
return bestMatch;
}
}