Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async getEnclosingCallerSymbol(reference: Location, context: CallHierarchyContext): Promise {
const allSymbols = await context.getAllSymbols(reference.uri);
if (allSymbols.length === 0) {
return undefined;
}
if (DocumentSymbol.is(allSymbols[0])) {
return this.getEnclosingRootSymbol(reference, context);
}
const symbols = (allSymbols as SymbolInformation[]).filter(s => this.isCallable(s));
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;
}
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;
}
}
async getEnclosingCallerSymbol(reference: Location, context: CallHierarchyContext): Promise {
const allSymbols = await context.getAllSymbols(reference.uri);
if (allSymbols.length === 0) {
return undefined;
}
if (DocumentSymbol.is(allSymbols[0])) {
return this.getEnclosingRootSymbol(reference, context);
}
const symbols = (allSymbols as SymbolInformation[]).filter(s => this.isCallable(s));
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;
}
}