Search in sources :

Example 1 with RenameRequest

use of org.lxtk.lx4e.requests.RenameRequest 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)

Aggregations

CompletionException (java.util.concurrent.CompletionException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)1 RenameParams (org.eclipse.lsp4j.RenameParams)1 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)1 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)1 DefaultWorkDoneProgress (org.lxtk.DefaultWorkDoneProgress)1 RenameProvider (org.lxtk.RenameProvider)1 PrepareRenameRequest (org.lxtk.lx4e.requests.PrepareRenameRequest)1 RenameRequest (org.lxtk.lx4e.requests.RenameRequest)1