From 8ec39afa0fd4cd2d4c23e9818ed192149bc30292 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Tue, 26 Apr 2016 17:39:17 +0300 Subject: [PATCH] inspection tool window: do not collect task in change updater --- .../InspectionViewPsiTreeChangeAdapter.java | 87 +++++++++++-------- 1 file changed, 50 insertions(+), 37 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionViewPsiTreeChangeAdapter.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionViewPsiTreeChangeAdapter.java index a06da6a9f82f..e9f9dd781a6d 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionViewPsiTreeChangeAdapter.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionViewPsiTreeChangeAdapter.java @@ -20,6 +20,7 @@ import com.intellij.codeInspection.reference.RefEntity; import com.intellij.concurrency.JobSchedulerImpl; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.util.ProgressIndicatorUtils; import com.intellij.openapi.progress.util.ReadTask; import com.intellij.openapi.project.Project; @@ -44,6 +45,8 @@ import java.util.Set; * @author Dmitry Batkovich */ class InspectionViewPsiTreeChangeAdapter extends PsiTreeChangeAdapter { + private final static int MAX_UPDATES_FOR_CANCELLABLE_ACTION = 100; + private final InspectionResultsView myView; private final MergingUpdateQueue myUpdater; private final BoundedTaskExecutor myExecutor; @@ -74,60 +77,70 @@ class InspectionViewPsiTreeChangeAdapter extends PsiTreeChangeAdapter { } }); } - final Project project = view.getProject(); - synchronized (myView.getTreeStructureUpdateLock()) { - InspectionTreeNode root = myView.getTree().getRoot(); - boolean[] needUpdateUI = {false}; - processNodesIfNeed(root, (node) -> { - if (node instanceof CachedInspectionTreeNode) { - //indicator.checkCanceled(); - RefEntity element = ((CachedInspectionTreeNode)node).getElement(); - if (element instanceof RefElement) { - final SmartPsiElementPointer pointer = ((RefElement)element).getPointer(); - VirtualFile strictVirtualFile = pointer.getVirtualFile(); - if (strictVirtualFile == null || !strictVirtualFile.isValid()) { - final PsiFile file = pointer.getContainingFile(); - if (file != null && file.isValid()) { - strictVirtualFile = file.getVirtualFile(); + + final Runnable runnable = () -> { + synchronized (myView.getTreeStructureUpdateLock()) { + InspectionTreeNode root = myView.getTree().getRoot(); + boolean[] needUpdateUI = {false}; + processNodesIfNeed(root, (node) -> { + if (node instanceof CachedInspectionTreeNode) { + RefEntity element = ((CachedInspectionTreeNode)node).getElement(); + if (element instanceof RefElement) { + final SmartPsiElementPointer pointer = ((RefElement)element).getPointer(); + VirtualFile strictVirtualFile = pointer.getVirtualFile(); + if (strictVirtualFile == null || !strictVirtualFile.isValid()) { + final PsiFile file = pointer.getContainingFile(); + if (file != null && file.isValid()) { + strictVirtualFile = file.getVirtualFile(); + } } + if (strictVirtualFile == null || files.contains(strictVirtualFile)) { + ((CachedInspectionTreeNode)node).dropCache(project); + if (!needUpdateUI[0]) { + needUpdateUI[0] = true; + } + } + return false; } - if (strictVirtualFile == null || files.contains(strictVirtualFile)) { + else { ((CachedInspectionTreeNode)node).dropCache(project); if (!needUpdateUI[0]) { needUpdateUI[0] = true; } + return false; } - return false; - } - else { - ((CachedInspectionTreeNode)node).dropCache(project); - if (!needUpdateUI[0]) { - needUpdateUI[0] = true; - } - return false; - } - } - return true; - }); - if (needUpdateUI[0]) { - UIUtil.invokeLaterIfNeeded(() -> { - myView.invalidate(); - myView.repaint(); - if (myView.isUpdating()) { - myView.updateRightPanelLoading(); - } else { - myView.syncRightPanel(); } + return true; }); + if (needUpdateUI[0]) { + UIUtil.invokeLaterIfNeeded(() -> { + myView.invalidate(); + myView.repaint(); + if (myView.isUpdating()) { + myView.updateRightPanelLoading(); + } + else { + myView.syncRightPanel(); + } + }); + } } + }; + + if (updates.length > MAX_UPDATES_FOR_CANCELLABLE_ACTION) { + ProgressManager.getInstance().executeNonCancelableSection(runnable); + } else { + runnable.run(); } } @Override public void onCanceled(@NotNull ProgressIndicator indicator) { if (!myView.isDisposed()) { - ProgressIndicatorUtils.scheduleWithWriteActionPriority(myExecutor, this); + for (Update update : updates) { + myUpdater.queue(update); + } } } };