Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}