Search in sources :

Example 1 with DefaultWorkDoneProgress

use of org.lxtk.DefaultWorkDoneProgress 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)

Example 2 with DefaultWorkDoneProgress

use of org.lxtk.DefaultWorkDoneProgress in project lxtk by lxtk-org.

the class RenameRefactoring method checkFinalConditions.

@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    RenameProvider[] renameProviders = getRenameProviders();
    if (renameProviders.length == 0)
        return RefactoringStatus.createFatalErrorStatus(Messages.RenameRefactoring_No_rename_provider);
    RefactoringStatus status = checkNewName();
    if (status.hasFatalError())
        return status;
    WorkspaceEdit workspaceEdit = null;
    int i = 0;
    if (prepareRenameProvider != null)
        while (i < renameProviders.length && renameProviders[i] != prepareRenameProvider) i++;
    SubMonitor subMonitor = SubMonitor.convert(pm, renameProviders.length - i);
    while (i < renameProviders.length) {
        RenameProvider renameProvider = renameProviders[i++];
        RenameRequest request = newRenameRequest();
        request.setProvider(renameProvider);
        request.setParams(new RenameParams(DocumentUri.toTextDocumentIdentifier(target.getDocumentUri()), getPosition(), getNewName()));
        request.setProgressMonitor(subMonitor.split(1));
        request.setUpWorkDoneProgress(() -> new DefaultWorkDoneProgress(Either.forLeft(UUID.randomUUID().toString())));
        try {
            workspaceEdit = request.sendAndReceive();
        } catch (CompletionException e) {
            status.merge(handleError(e.getCause(), request.getErrorMessage()));
        }
        if (workspaceEdit != null) {
            setWorkspaceEdit(workspaceEdit);
            return super.checkFinalConditions(null);
        }
    }
    // no workspace edit
    if (!status.hasFatalError())
        status.addFatalError(Messages.RenameRefactoring_No_workspace_edit);
    return status;
}
Also used : RenameProvider(org.lxtk.RenameProvider) RenameParams(org.eclipse.lsp4j.RenameParams) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) CompletionException(java.util.concurrent.CompletionException) SubMonitor(org.eclipse.core.runtime.SubMonitor) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RenameRequest(org.lxtk.lx4e.requests.RenameRequest) PrepareRenameRequest(org.lxtk.lx4e.requests.PrepareRenameRequest) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) DefaultWorkDoneProgress(org.lxtk.DefaultWorkDoneProgress)

Example 3 with DefaultWorkDoneProgress

use of org.lxtk.DefaultWorkDoneProgress in project lxtk by lxtk-org.

the class CallHierarchyUtility method getIncomingCalls.

/**
 * Returns the incoming calls for the given call hierarchy item.
 *
 * @param item not <code>null</code>
 * @param monitor a progress monitor, or <code>null</code>
 *  if progress reporting is not desired. The caller must not rely on
 *  {@link IProgressMonitor#done()} having been called by the receiver
 * @return a list of incoming calls (may be <code>null</code> or empty)
 */
public List<CallHierarchyIncomingCall> getIncomingCalls(CallHierarchyItem item, IProgressMonitor monitor) {
    CallHierarchyIncomingCallsRequest request = newIncomingCallsRequest();
    request.setProvider(provider);
    request.setParams(new CallHierarchyIncomingCallsParams(item));
    request.setProgressMonitor(monitor);
    request.setUpWorkDoneProgress(() -> new DefaultWorkDoneProgress(Either.forLeft(UUID.randomUUID().toString())));
    request.setMayThrow(false);
    return request.sendAndReceive();
}
Also used : CallHierarchyIncomingCallsParams(org.eclipse.lsp4j.CallHierarchyIncomingCallsParams) DefaultWorkDoneProgress(org.lxtk.DefaultWorkDoneProgress) CallHierarchyIncomingCallsRequest(org.lxtk.lx4e.requests.CallHierarchyIncomingCallsRequest)

Example 4 with DefaultWorkDoneProgress

use of org.lxtk.DefaultWorkDoneProgress in project lxtk by lxtk-org.

the class CallHierarchyUtility method getOutgoingCalls.

/**
 * Returns the outgoing calls for the given call hierarchy item.
 *
 * @param item not <code>null</code>
 * @param monitor a progress monitor, or <code>null</code>
 *  if progress reporting is not desired. The caller must not rely on
 *  {@link IProgressMonitor#done()} having been called by the receiver
 * @return a list of outgoing calls (may be <code>null</code> or empty)
 */
public List<CallHierarchyOutgoingCall> getOutgoingCalls(CallHierarchyItem item, IProgressMonitor monitor) {
    CallHierarchyOutgoingCallsRequest request = newOutgoingCallsRequest();
    request.setProvider(provider);
    request.setParams(new CallHierarchyOutgoingCallsParams(item));
    request.setProgressMonitor(monitor);
    request.setUpWorkDoneProgress(() -> new DefaultWorkDoneProgress(Either.forLeft(UUID.randomUUID().toString())));
    request.setMayThrow(false);
    return request.sendAndReceive();
}
Also used : DefaultWorkDoneProgress(org.lxtk.DefaultWorkDoneProgress) CallHierarchyOutgoingCallsParams(org.eclipse.lsp4j.CallHierarchyOutgoingCallsParams) CallHierarchyOutgoingCallsRequest(org.lxtk.lx4e.requests.CallHierarchyOutgoingCallsRequest)

Aggregations

DefaultWorkDoneProgress (org.lxtk.DefaultWorkDoneProgress)4 CompletionException (java.util.concurrent.CompletionException)2 ArrayList (java.util.ArrayList)1 CoreException (org.eclipse.core.runtime.CoreException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 CallHierarchyIncomingCallsParams (org.eclipse.lsp4j.CallHierarchyIncomingCallsParams)1 CallHierarchyOutgoingCallsParams (org.eclipse.lsp4j.CallHierarchyOutgoingCallsParams)1 DocumentSymbol (org.eclipse.lsp4j.DocumentSymbol)1 DocumentSymbolParams (org.eclipse.lsp4j.DocumentSymbolParams)1 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)1 RenameParams (org.eclipse.lsp4j.RenameParams)1 SymbolInformation (org.eclipse.lsp4j.SymbolInformation)1 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)1 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)1 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)1 RenameProvider (org.lxtk.RenameProvider)1 CallHierarchyIncomingCallsRequest (org.lxtk.lx4e.requests.CallHierarchyIncomingCallsRequest)1 CallHierarchyOutgoingCallsRequest (org.lxtk.lx4e.requests.CallHierarchyOutgoingCallsRequest)1 DocumentSymbolRequest (org.lxtk.lx4e.requests.DocumentSymbolRequest)1 PrepareRenameRequest (org.lxtk.lx4e.requests.PrepareRenameRequest)1