Skip to content

Commit

Permalink
fix: LSP rename is shown when Java variable is renamed.
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Jul 1, 2024
1 parent 918187b commit 360c0df
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
import com.intellij.psi.PsiFile;
import com.intellij.refactoring.rename.RenameHandler;
import com.intellij.refactoring.rename.RenameHandlerRegistry;
import com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler;
import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler;
import com.redhat.devtools.lsp4ij.*;
import com.redhat.devtools.lsp4ij.internal.CancellationUtil;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;

import static com.redhat.devtools.lsp4ij.internal.CompletableFutures.waitUntilDoneAsync;

Expand Down Expand Up @@ -187,15 +189,15 @@ public boolean isAvailableOnDataContext(@NotNull DataContext dataContext) {
if (renameHandlers.isEmpty()) {
return true;
}
// When there are several rename handlers, IJ removes all MemberInplaceRenameHandlers (ex: inline Java field rename)
// When there are several rename handlers, IJ removes all VariableInplaceRenameHandler, MemberInplaceRenameHandlers (ex: inline Java field rename)
// See https://github.com/JetBrains/intellij-community/blob/cc10f72bc90a650b8d9d9f0427ae5a56111940dd/platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandlerRegistry.java#L106
// To avoid showing the LSP Rename dialog when a Java field is renamed (which will do nothing)
// We want to show the IJ inline variable rename handler instead of LSP rename dialog.
// So we check none of them is an instance of MemberInplaceRenameHandler,
// in which case, the LSP rename dialog will not be available
return !renameHandlers
.stream()
.allMatch(renameHandler -> renameHandler instanceof MemberInplaceRenameHandler);
.allMatch(renameHandler -> renameHandler instanceof VariableInplaceRenameHandler);
} finally {
searchingRenameHandlers = false;
}
Expand Down

0 comments on commit 360c0df

Please sign in to comment.