mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[inspections] Start batch quick-fixes in commands
Fixes IDEA-368193 Quick-fix fails when invoked from batch inspection results GitOrigin-RevId: b72e4bd0dfbe48f5ee9e1537cabbaa873144df26
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6d7ef89b5a
commit
2e8c27b68e
@@ -140,7 +140,10 @@ public final class LocalQuickFixWrapper extends QuickFixAction {
|
||||
@NotNull GlobalInspectionContextImpl context,
|
||||
Set<? super PsiElement> ignoredElements) {
|
||||
if (myFix instanceof BatchQuickFix) {
|
||||
applyFix(project, context, BatchModeDescriptorsUtil.flattenDescriptors(descriptors), ignoredElements);
|
||||
executeAndNotify(project, () -> {
|
||||
BatchExecutionResult result = applyFix(project, context, BatchModeDescriptorsUtil.flattenDescriptors(descriptors), ignoredElements);
|
||||
return result.getMessage();
|
||||
});
|
||||
}
|
||||
else {
|
||||
super.performFixesInBatch(project, descriptors, context, ignoredElements);
|
||||
|
||||
@@ -49,6 +49,7 @@ import javax.swing.*;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class QuickFixAction extends AnAction implements CustomComponentAction {
|
||||
private static final Logger LOG = Logger.getInstance(QuickFixAction.class);
|
||||
@@ -175,14 +176,14 @@ public abstract class QuickFixAction extends AnAction implements CustomComponent
|
||||
Set<? super PsiElement> ignoredElements) {
|
||||
final String templatePresentationText = getTemplatePresentation().getText();
|
||||
assert templatePresentationText != null;
|
||||
Ref<@Nls String> messageRef = Ref.create();
|
||||
CommandProcessor.getInstance().executeCommand(project, () -> {
|
||||
executeAndNotify(project, () -> {
|
||||
CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
|
||||
boolean startInWriteAction = startInWriteAction();
|
||||
PerformFixesTask performFixesTask = new PerformFixesTask(project, descriptors, ignoredElements, context);
|
||||
if (startInWriteAction) {
|
||||
((ApplicationImpl)ApplicationManager.getApplication())
|
||||
.runWriteActionWithCancellableProgressInDispatchThread(templatePresentationText, project, null, performFixesTask::doRun);
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
final SequentialModalProgressTask progressTask =
|
||||
@@ -190,9 +191,16 @@ public abstract class QuickFixAction extends AnAction implements CustomComponent
|
||||
progressTask.setMinIterationTime(200);
|
||||
progressTask.setTask(performFixesTask);
|
||||
ProgressManager.getInstance().run(progressTask);
|
||||
messageRef.set(performFixesTask.getResultMessage(templatePresentationText));
|
||||
return performFixesTask.getResultMessage(templatePresentationText);
|
||||
}
|
||||
}, templatePresentationText, null);
|
||||
});
|
||||
}
|
||||
|
||||
void executeAndNotify(@NotNull Project project, @NotNull Supplier<@Nls String> command) {
|
||||
final String templatePresentationText = getTemplatePresentation().getText();
|
||||
assert templatePresentationText != null;
|
||||
Ref<@Nls String> messageRef = Ref.create();
|
||||
CommandProcessor.getInstance().executeCommand(project, () -> messageRef.set(command.get()), templatePresentationText, null);
|
||||
String message = messageRef.get();
|
||||
if (message != null) {
|
||||
BATCH_QUICK_FIX_MESSAGES.createNotification(HtmlChunk.text(message).toString(), NotificationType.WARNING)
|
||||
|
||||
Reference in New Issue
Block a user