Skip to content

Commit 0e53c80

Browse files
committed
fix: Irrelevant Quick Fixes after applying code action
Fixes redhat-developer#410 Signed-off-by: azerr <[email protected]>
1 parent e3f1d6e commit 0e53c80

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/LSPLazyCodeActionIntentionAction.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,26 @@ private void apply(@Nullable CodeAction codeaction,
122122
executeCommand(codeaction.getCommand(), file, editor, languageServerItem);
123123
}
124124
}
125+
// After applying code action, evict the code actions cache
126+
// to avoid providing irrelevant Quick Fixes.
127+
clearCodeActionsCache();
125128
}
126129

127-
private static void executeCommand(@NotNull Command command,
130+
/**
131+
* Clear code actions cache if needed.
132+
*/
133+
private void clearCodeActionsCache() {
134+
if (lazyCodeActions != null) {
135+
lazyCodeActions.clear();
136+
}
137+
}
138+
139+
private void executeCommand(@NotNull Command command,
128140
@NotNull PsiFile file,
129141
@NotNull Editor editor,
130142
@NotNull LanguageServerItem languageServer) {
131143
CommandExecutor.executeCommand(new LSPCommandContext(command, file, LSPCommandContext.ExecutedBy.CODE_ACTION, editor, languageServer));
144+
clearCodeActionsCache();
132145
}
133146

134147
private LanguageServerItem getLanguageServer() {

src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/LSPLazyCodeActionProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ public interface LSPLazyCodeActionProvider {
2424
* @return a code action at the given index and false otherwise.
2525
*/
2626
Either<CodeActionData, Boolean /* false when code action is not already loaded*/> getCodeActionAt(int index);
27+
28+
/**
29+
* Clear code actions cache.
30+
*/
31+
void clear();
2732
}

src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/intention/LSPIntentionCodeActionSupport.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,9 @@ private static boolean isValidCodeAction(@Nullable Either<org.eclipse.lsp4j.Comm
145145
}
146146
return true;
147147
}
148+
149+
@Override
150+
public void clear() {
151+
super.cancel();
152+
}
148153
}

src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/quickfix/LSPLazyCodeActions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,10 @@ public void cancel() {
193193
lspCodeActionRequest.cancel(true);
194194
}
195195
}
196+
197+
@Override
198+
public void clear() {
199+
cancel();
200+
lspCodeActionRequest = null;
201+
}
196202
}

0 commit comments

Comments
 (0)