diff --git a/src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/LSPLazyCodeActionIntentionAction.java b/src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/LSPLazyCodeActionIntentionAction.java index 97bc4640c..ca1968be2 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/LSPLazyCodeActionIntentionAction.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/LSPLazyCodeActionIntentionAction.java @@ -120,13 +120,26 @@ private void apply(@Nullable CodeAction codeaction, executeCommand(codeaction.getCommand(), file, editor, languageServerItem); } } + // After applying code action, evict the code actions cache + // to avoid providing irrelevant Quick Fixes. + clearCodeActionsCache(); } - private static void executeCommand(@NotNull Command command, + private void executeCommand(@NotNull Command command, @NotNull PsiFile file, @NotNull Editor editor, @NotNull LanguageServerItem languageServer) { CommandExecutor.executeCommand(new LSPCommandContext(command, file, LSPCommandContext.ExecutedBy.CODE_ACTION, editor, languageServer)); + clearCodeActionsCache(); + } + + /** + * Clear code actions cache if needed. + */ + private void clearCodeActionsCache() { + if (lazyCodeActions != null) { + lazyCodeActions.clear(); + } } private LanguageServerItem getLanguageServer() { @@ -176,4 +189,11 @@ private boolean isValidCodeAction() { return action != null && action.isLeft(); } + public void clear() { + action = null; + title = null; + familyName= LanguageServerBundle.message("lsp.intention.code.action.kind.empty"); + codeAction = null; + command = null; + } } diff --git a/src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/LSPLazyCodeActionProvider.java b/src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/LSPLazyCodeActionProvider.java index 2a9008cc6..3806bc2b2 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/LSPLazyCodeActionProvider.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/LSPLazyCodeActionProvider.java @@ -24,4 +24,9 @@ public interface LSPLazyCodeActionProvider { * @return a code action at the given index and false otherwise. */ Either getCodeActionAt(int index); + + /** + * Clear code actions cache. + */ + void clear(); } diff --git a/src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/intention/LSPIntentionCodeActionSupport.java b/src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/intention/LSPIntentionCodeActionSupport.java index bfe381e41..aac21a682 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/intention/LSPIntentionCodeActionSupport.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/intention/LSPIntentionCodeActionSupport.java @@ -51,7 +51,7 @@ public CompletableFuture> getCodeActions(CodeActionParams p super.cancel(); } previousParams = params; - return super.getFeatureData(params); + return CompletableFuture.completedFuture(Collections.emptyList()); //super.getFeatureData(params); } @Override @@ -142,4 +142,9 @@ private static boolean isValidCodeAction(@Nullable Either ((LSPLazyCodeActionIntentionAction)ca).clear()); + } }