Search in sources :

Example 1 with PrepareRenameRequest

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

the class RenameRefactoring method checkInitialConditions.

@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    setPrepareRenameResult(null, null);
    RenameProvider[] renameProviders = getRenameProviders();
    if (renameProviders.length == 0)
        return RefactoringStatus.createFatalErrorStatus(Messages.RenameRefactoring_No_rename_provider);
    RefactoringStatus status = new RefactoringStatus();
    SubMonitor subMonitor = SubMonitor.convert(pm, renameProviders.length);
    for (int i = 0; i < renameProviders.length; i++) {
        RenameProvider renameProvider = renameProviders[i];
        if (!Boolean.TRUE.equals(renameProvider.getRegistrationOptions().getPrepareProvider()))
            return new RefactoringStatus();
        PrepareRenameRequest request = newPrepareRenameRequest();
        request.setProvider(renameProvider);
        PrepareRenameParams params = new PrepareRenameParams(DocumentUri.toTextDocumentIdentifier(target.getDocumentUri()), getPosition());
        request.setParams(params);
        request.setProgressMonitor(subMonitor.split(1));
        Either<Range, PrepareRenameResult> prepareRenameResult = null;
        try {
            prepareRenameResult = request.sendAndReceive();
        } catch (CompletionException e) {
            status.merge(handleError(e.getCause(), request.getErrorMessage()));
        }
        if (prepareRenameResult != null) {
            setPrepareRenameResult(renameProvider, prepareRenameResult);
            return new RefactoringStatus();
        }
    }
    // no prepare rename result
    if (!status.hasFatalError())
        status.addFatalError(Messages.RenameRefactoring_No_prepare_rename_result);
    return status;
}
Also used : RenameProvider(org.lxtk.RenameProvider) CompletionException(java.util.concurrent.CompletionException) SubMonitor(org.eclipse.core.runtime.SubMonitor) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) PrepareRenameResult(org.eclipse.lsp4j.PrepareRenameResult) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) Range(org.eclipse.lsp4j.Range) PrepareRenameRequest(org.lxtk.lx4e.requests.PrepareRenameRequest)

Aggregations

CompletionException (java.util.concurrent.CompletionException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)1 PrepareRenameResult (org.eclipse.lsp4j.PrepareRenameResult)1 Range (org.eclipse.lsp4j.Range)1 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)1 RenameProvider (org.lxtk.RenameProvider)1 PrepareRenameRequest (org.lxtk.lx4e.requests.PrepareRenameRequest)1