Skip to content

Commit

Permalink
fix: Irrelevant Quick Fixes after applying code action
Browse files Browse the repository at this point in the history
Fixes redhat-developer#410

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Jul 6, 2024
1 parent e3f1d6e commit 0e53c80
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ public interface LSPLazyCodeActionProvider {
* @return a code action at the given index and false otherwise.
*/
Either<CodeActionData, Boolean /* false when code action is not already loaded*/> getCodeActionAt(int index);

/**
* Clear code actions cache.
*/
void clear();
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,9 @@ private static boolean isValidCodeAction(@Nullable Either<org.eclipse.lsp4j.Comm
}
return true;
}

@Override
public void clear() {
super.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,10 @@ public void cancel() {
lspCodeActionRequest.cancel(true);
}
}

@Override
public void clear() {
cancel();
lspCodeActionRequest = null;
}
}

0 comments on commit 0e53c80

Please sign in to comment.