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 cafd38736..675cadd4e 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
@@ -122,13 +122,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,
+ /**
+ * Clear code actions cache if needed.
+ */
+ private void clearCodeActionsCache() {
+ if (lazyCodeActions != null) {
+ lazyCodeActions.clear();
+ }
+ }
+
+ 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();
}
private LanguageServerItem getLanguageServer() {
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 e72481783..e1b5e92bb 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
@@ -145,4 +145,9 @@ private static boolean isValidCodeAction(@Nullable Either