Search in sources :

Example 16 with PrepareRenameResult

use of org.eclipse.lsp4j.PrepareRenameResult in project magik-tools by StevenLooman.

the class RenameProviderTest method testPrepareRenameLocal.

@Test
void testPrepareRenameLocal() {
    final String code = "" + "_block\n" + "    _local var\n" + "    show(var)\n" + "_endblock\n";
    // On `var`.
    final Position position = new Position(1, 12);
    final Either<Range, PrepareRenameResult> either = this.getPrepareRename(code, position);
    assertThat(either).isNotNull();
    final PrepareRenameResult prepareRenameResult = either.getRight();
    assertThat(prepareRenameResult.getRange()).isEqualTo(new Range(new Position(1, 11), new Position(1, 14)));
    assertThat(prepareRenameResult.getPlaceholder()).isEqualTo("var");
}
Also used : Position(org.eclipse.lsp4j.Position) PrepareRenameResult(org.eclipse.lsp4j.PrepareRenameResult) Range(org.eclipse.lsp4j.Range) Test(org.junit.jupiter.api.Test)

Example 17 with PrepareRenameResult

use of org.eclipse.lsp4j.PrepareRenameResult 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

PrepareRenameResult (org.eclipse.lsp4j.PrepareRenameResult)17 Range (org.eclipse.lsp4j.Range)16 Position (org.eclipse.lsp4j.Position)14 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)9 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)9 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)9 Test (org.junit.Test)9 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)5 RenameParams (org.eclipse.lsp4j.RenameParams)3 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)3 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)3 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.jupiter.api.Test)2 JsonArray (com.google.gson.JsonArray)1 AstNode (com.sonar.sslr.api.AstNode)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1