How to use the @theia/callhierarchy/lib/browser/utils.startsAfter function in @theia/callhierarchy

To help you get started, we’ve selected a few @theia/callhierarchy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipse-theia / theia / packages / typescript / src / browser / typescript-callhierarchy-service.ts View on Github external
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;
    }
}

@theia/callhierarchy

Theia - Call Hierarchy Extension

EPL-2.0
Latest version published 20 days ago

Package Health Score

87 / 100
Full package analysis