Search in sources :

Example 1 with DocumentSymbolRequest

use of org.lxtk.lx4e.requests.DocumentSymbolRequest in project lxtk by lxtk-org.

the class LanguageSourceFile method getDocumentSymbols.

private List<DocumentSymbol> getDocumentSymbols(DocumentSymbolProvider provider, URI documentUri, IProgressMonitor monitor) throws CoreException {
    DocumentSymbolRequest request = newDocumentSymbolRequest();
    request.setProvider(provider);
    request.setParams(new DocumentSymbolParams(DocumentUri.toTextDocumentIdentifier(documentUri)));
    request.setTimeout(getDocumentSymbolTimeout());
    request.setProgressMonitor(monitor);
    request.setUpWorkDoneProgress(() -> new DefaultWorkDoneProgress(Either.forLeft(UUID.randomUUID().toString())));
    List<Either<SymbolInformation, DocumentSymbol>> result;
    try {
        result = request.sendAndReceive();
    } catch (CompletionException e) {
        throw new CoreException(Activator.createErrorStatus(request.getErrorMessage(), e.getCause()));
    }
    if (result == null || result.isEmpty() || result.get(0).isLeft())
        return Collections.emptyList();
    List<DocumentSymbol> symbols = new ArrayList<>(result.size());
    for (Either<SymbolInformation, DocumentSymbol> item : result) {
        if (item.isRight())
            symbols.add(item.getRight());
    }
    return symbols;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) CompletionException(java.util.concurrent.CompletionException) ArrayList(java.util.ArrayList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) DocumentSymbolRequest(org.lxtk.lx4e.requests.DocumentSymbolRequest) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) DefaultWorkDoneProgress(org.lxtk.DefaultWorkDoneProgress) SymbolInformation(org.eclipse.lsp4j.SymbolInformation)

Aggregations

ArrayList (java.util.ArrayList)1 CompletionException (java.util.concurrent.CompletionException)1 CoreException (org.eclipse.core.runtime.CoreException)1 DocumentSymbol (org.eclipse.lsp4j.DocumentSymbol)1 DocumentSymbolParams (org.eclipse.lsp4j.DocumentSymbolParams)1 SymbolInformation (org.eclipse.lsp4j.SymbolInformation)1 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)1 DefaultWorkDoneProgress (org.lxtk.DefaultWorkDoneProgress)1 DocumentSymbolRequest (org.lxtk.lx4e.requests.DocumentSymbolRequest)1