diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunner.java b/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunner.java index 1364b024c309..7372cb43d0f7 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunner.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunner.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.debugger.impl; import com.intellij.debugger.DebugEnvironment; @@ -23,6 +23,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.SlowOperations; import com.intellij.xdebugger.XDebugProcess; import com.intellij.xdebugger.XDebugProcessStarter; import com.intellij.xdebugger.XDebugSession; @@ -66,9 +67,9 @@ public class GenericDebuggerRunner implements JvmPatchableProgramRunner { + executionManager.startRunProfile(environment, state, state1 -> SlowOperations.allowSlowOperations(() -> { return doExecute(state, environment); - }); + })); } } diff --git a/java/execution/impl/src/com/intellij/execution/impl/DefaultJavaProgramRunner.java b/java/execution/impl/src/com/intellij/execution/impl/DefaultJavaProgramRunner.java index df39993d3ea3..6f2dd195e7b5 100644 --- a/java/execution/impl/src/com/intellij/execution/impl/DefaultJavaProgramRunner.java +++ b/java/execution/impl/src/com/intellij/execution/impl/DefaultJavaProgramRunner.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.impl; import com.intellij.debugger.engine.JavaDebugProcess; @@ -43,6 +43,7 @@ import com.intellij.unscramble.ThreadDumpConsoleFactory; import com.intellij.unscramble.ThreadDumpParser; import com.intellij.unscramble.ThreadState; import com.intellij.util.ArrayUtil; +import com.intellij.util.SlowOperations; import com.intellij.util.TimeoutUtil; import com.intellij.util.concurrency.AppExecutorUtil; import com.intellij.util.messages.MessageBusConnection; @@ -112,9 +113,9 @@ public class DefaultJavaProgramRunner implements JvmPatchableProgramRunner { + executionManager.startRunProfile(environment, currentState, (ignored) -> SlowOperations.allowSlowOperations(() -> { return doExecute(currentState, environment); - }); + })); } } diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java b/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java index 7da5fe44f0f1..fa558b7b0c22 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.completion; import com.intellij.codeInsight.ExpectedTypeInfo; @@ -38,6 +38,7 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiTypesUtil; import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.SlowOperations; import com.intellij.util.ThreeState; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.Contract; @@ -316,7 +317,7 @@ public final class ConstructorInsertHandler implements InsertHandler { + CommandProcessor.getInstance().executeCommand(project, () -> SlowOperations.allowSlowOperations(() -> { final Collection candidatesToImplement = OverrideImplementExploreUtil.getMethodsToOverrideImplement(aClass, true); for (Iterator iterator = candidatesToImplement.iterator(); iterator.hasNext(); ) { final CandidateInfo candidate = iterator.next(); @@ -343,7 +344,7 @@ public final class ConstructorInsertHandler implements InsertHandler { public boolean canRepresent(final Object element) { if (!isValid()) return false; - return super.canRepresent(element) || canRepresent(getValue(), element); + return super.canRepresent(element) || SlowOperations.allowSlowOperations(() -> canRepresent(getValue(), element)); } private boolean canRepresent(final PsiClass psiClass, final Object element) { diff --git a/java/java-impl/src/com/intellij/lang/java/JavaImportOptimizer.java b/java/java-impl/src/com/intellij/lang/java/JavaImportOptimizer.java index fe23835a3c87..2bdf63a161f2 100644 --- a/java/java-impl/src/com/intellij/lang/java/JavaImportOptimizer.java +++ b/java/java-impl/src/com/intellij/lang/java/JavaImportOptimizer.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.lang.java; @@ -15,6 +15,7 @@ import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.templateLanguages.TemplateLanguageUtil; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.SlowOperations; import org.jetbrains.annotations.NotNull; public class JavaImportOptimizer implements ImportOptimizer { @@ -36,6 +37,10 @@ public class JavaImportOptimizer implements ImportOptimizer { @Override public void run() { + SlowOperations.allowSlowOperations(() -> doRun()); + } + + private void doRun() { try { final PsiDocumentManager manager = PsiDocumentManager.getInstance(file.getProject()); final Document document = manager.getDocument(file); diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java index aa0b7048b2b0..b0266e7e86c9 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.refactoring.introduceVariable; import com.intellij.codeInsight.CodeInsightUtil; @@ -60,6 +60,7 @@ import com.intellij.refactoring.util.occurrences.ExpressionOccurrenceManager; import com.intellij.refactoring.util.occurrences.NotInSuperCallOccurrenceFilter; import com.intellij.util.IncorrectOperationException; import com.intellij.util.Processor; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; import com.siyeh.ig.psiutils.CommentTracker; @@ -692,7 +693,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase { @Override public void pass(final JavaReplaceChoice choice) { - if (choice == null || !tryIntroduceInplace(project, editor, choice, occurrenceManager, originalType)) { + if (choice == null || !SlowOperations.allowSlowOperations(() -> tryIntroduceInplace(project, editor, choice, occurrenceManager, originalType))) { CommandProcessor.getInstance().executeCommand(project, () -> introduce(choice), getRefactoringName(), null); } } diff --git a/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java b/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java index 08739782ecc5..b96783730ac2 100644 --- a/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java +++ b/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java @@ -1,10 +1,11 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.structureView.impl.java; import com.intellij.ide.structureView.StructureViewTreeElement; import com.intellij.psi.*; import com.intellij.psi.impl.PsiImplUtil; import com.intellij.psi.impl.light.LightElement; +import com.intellij.util.SlowOperations; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -58,6 +59,10 @@ public class JavaClassTreeElement extends JavaClassTreeElementBase { } static LinkedHashSet getOwnChildren(@NotNull PsiClass aClass) { + return SlowOperations.allowSlowOperations(() -> doGetOwnChildren(aClass)); + } + + private static @NotNull LinkedHashSet doGetOwnChildren(@NotNull PsiClass aClass) { LinkedHashSet members = new LinkedHashSet<>(); addPhysicalElements(aClass.getFields(), members, aClass); addPhysicalElements(aClass.getMethods(), members, aClass); diff --git a/java/openapi/src/com/intellij/execution/filters/ExceptionWorker.java b/java/openapi/src/com/intellij/execution/filters/ExceptionWorker.java index 6f18400fbba5..e8eec04a3e59 100644 --- a/java/openapi/src/com/intellij/execution/filters/ExceptionWorker.java +++ b/java/openapi/src/com/intellij/execution/filters/ExceptionWorker.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.filters; import com.intellij.execution.filters.ExceptionAnalysisProvider.StackLine; @@ -28,6 +28,7 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.ui.HyperlinkAdapter; import com.intellij.ui.awt.RelativePoint; import com.intellij.util.ObjectUtils; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -406,7 +407,8 @@ public class ExceptionWorker { PsiElement element = file.findElementAt(startOffset); List candidates = new ArrayList<>(); while (element != null && element.getTextRange().getStartOffset() < endOffset) { - PsiElement matched = myElementMatcher.matchElement(element); + PsiElement finalElement = element; + PsiElement matched = SlowOperations.allowSlowOperations(() -> myElementMatcher.matchElement(finalElement)); if (matched != null) { candidates.add(matched); if (candidates.size() > 1) return; @@ -417,7 +419,7 @@ public class ExceptionWorker { PsiElement foundElement = candidates.get(0); TextRange range = foundElement.getTextRange(); targetEditor.getCaretModel().moveToOffset(range.getStartOffset()); - displayAnalysisAction(file.getProject(), foundElement, targetEditor, originalEditor); + SlowOperations.allowSlowOperations(() -> displayAnalysisAction(file.getProject(), foundElement, targetEditor, originalEditor)); } } diff --git a/platform/analysis-api/src/com/intellij/codeInsight/daemon/ProblemHighlightFilter.java b/platform/analysis-api/src/com/intellij/codeInsight/daemon/ProblemHighlightFilter.java index 40f04c613591..bb6d239ca3e5 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/daemon/ProblemHighlightFilter.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/daemon/ProblemHighlightFilter.java @@ -1,22 +1,9 @@ -/* - * Copyright 2000-2010 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.daemon; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.psi.PsiFile; +import com.intellij.util.SlowOperations; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -40,7 +27,7 @@ public abstract class ProblemHighlightFilter { } public static boolean shouldHighlightFile(@Nullable final PsiFile psiFile) { - return shouldProcess(psiFile, true); + return SlowOperations.allowSlowOperations(() -> shouldProcess(psiFile, true)); } public static boolean shouldProcessFileInBatch(@Nullable final PsiFile psiFile) { diff --git a/platform/code-style-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java b/platform/code-style-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java index 9d63f0964bac..0ff50e2e8914 100644 --- a/platform/code-style-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java +++ b/platform/code-style-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl.source; import com.intellij.application.options.CodeStyle; @@ -6,6 +6,7 @@ import com.intellij.formatting.FormatTextRanges; import com.intellij.lang.ASTNode; import com.intellij.lang.FileASTNode; import com.intellij.lang.injection.InjectedLanguageManager; +import com.intellij.model.ModelBranch; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationListener; @@ -32,7 +33,6 @@ import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.ExternalFormatProcessor; -import com.intellij.model.ModelBranch; import com.intellij.psi.impl.PsiDocumentManagerBase; import com.intellij.psi.impl.PsiManagerEx; import com.intellij.psi.impl.file.impl.FileManager; @@ -42,6 +42,7 @@ import com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl; import com.intellij.psi.impl.source.codeStyle.IndentHelperImpl; import com.intellij.psi.impl.source.tree.*; import com.intellij.util.Function; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.JBIterable; import com.intellij.util.containers.MultiMap; @@ -790,7 +791,7 @@ public final class PostprocessReformattingAspect implements PomModelAspect { } else { final CodeFormatterFacade codeFormatter = getFormatterFacade(viewProvider); - codeFormatter.processText(file, textRanges, false); + SlowOperations.allowSlowOperations(() -> codeFormatter.processText(file, textRanges, false)); } } diff --git a/platform/core-api/src/com/intellij/util/SlowOperations.java b/platform/core-api/src/com/intellij/util/SlowOperations.java index 7caa1100cd10..1e525b7f39ca 100644 --- a/platform/core-api/src/com/intellij/util/SlowOperations.java +++ b/platform/core-api/src/com/intellij/util/SlowOperations.java @@ -6,6 +6,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.registry.Registry; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import java.util.HashSet; @@ -15,23 +16,43 @@ public final class SlowOperations { private static final Logger LOG = Logger.getInstance(SlowOperations.class); private static final Set ourReportedTraces = new HashSet<>(); + private static final String[] misbehavingFrames = { + "org.jetbrains.kotlin.idea.refactoring.introduce.introduceVariable.KotlinIntroduceVariableHandler", + "org.jetbrains.kotlin.idea.actions.KotlinAddImportAction", + "org.jetbrains.kotlin.idea.codeInsight.KotlinCopyPasteReferenceProcessor", + "com.intellij.apiwatcher.plugin.presentation.bytecode.UsageHighlighter", + }; private static boolean ourAllowedFlag = false; private SlowOperations() {} + /** + * If you get an exception from this method, then you need to move the computation to the background + * while also trying to avoid blocking the UI thread as well. It's okay if the API changes in the process, + * e.g. instead of wrapping implementation of some extension into {@link #allowSlowOperations}, + * it's better to admit that the EP semantic as a whole requires index access, + * and then move the iteration over all extensions to the background on the platform-side. + *

+ * In cases when it's impossible to do so, the computation should be wrapped into {@code allowSlowOperations} explicitly. + * This way it's possible to find all such operations by searching usages of {@code allowSlowOperations}. + * + * @see com.intellij.openapi.application.NonBlockingReadAction + * @see com.intellij.openapi.application.CoroutinesKt#readAction + * @see com.intellij.openapi.actionSystem.ex.ActionUtil#underModalProgress + */ public static void assertSlowOperationsAreAllowed() { if (Registry.is("ide.enable.slow.operations.in.edt")) { return; } Application application = ApplicationManager.getApplication(); - if ( - !application.isUnitTestMode() && - application.isDispatchThread() && - !ourAllowedFlag && - ourReportedTraces.add(ExceptionUtil.currentStackTrace()) - ) { - LOG.error("Slow operations are prohibited in the EDT"); + if (application.isUnitTestMode() || !application.isDispatchThread() || ourAllowedFlag) { + return; } + String stackTrace = ExceptionUtil.currentStackTrace(); + if (ContainerUtil.or(misbehavingFrames, stackTrace::contains) || !ourReportedTraces.add(stackTrace)) { + return; + } + LOG.error("Slow operations are prohibited in the EDT"); } public static T allowSlowOperations(@NotNull ThrowableComputable computable) throws E { diff --git a/platform/editor-ui-api/src/com/intellij/ide/util/treeView/AbstractTreeNode.java b/platform/editor-ui-api/src/com/intellij/ide/util/treeView/AbstractTreeNode.java index 2c20e0a4cc9a..481d018109bc 100644 --- a/platform/editor-ui-api/src/com/intellij/ide/util/treeView/AbstractTreeNode.java +++ b/platform/editor-ui-api/src/com/intellij/ide/util/treeView/AbstractTreeNode.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.util.treeView; import com.intellij.ide.projectView.PresentationData; @@ -13,6 +13,7 @@ import com.intellij.openapi.vcs.FileStatus; import com.intellij.openapi.vcs.FileStatusManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.tree.LeafState; +import com.intellij.util.SlowOperations; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -145,7 +146,7 @@ public abstract class AbstractTreeNode extends PresentableNodeDescriptor TreeAnchorizer.getService().retrieveElement(value)); } public final void setValue(T value) { diff --git a/platform/execution-impl/src/com/intellij/execution/impl/statistics/RunConfigurationTypeUsagesCollector.java b/platform/execution-impl/src/com/intellij/execution/impl/statistics/RunConfigurationTypeUsagesCollector.java index 78dfa7c5bf5d..8522926ad8a4 100644 --- a/platform/execution-impl/src/com/intellij/execution/impl/statistics/RunConfigurationTypeUsagesCollector.java +++ b/platform/execution-impl/src/com/intellij/execution/impl/statistics/RunConfigurationTypeUsagesCollector.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.impl.statistics; import com.intellij.execution.RunManager; @@ -22,6 +22,7 @@ import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; import it.unimi.dsi.fastutil.objects.Object2IntMap; @@ -87,7 +88,9 @@ public final class RunConfigurationTypeUsagesCollector extends ProjectUsagesColl addOrIncrement(templates, template); collectRunConfigurationFeatures(runConfiguration, templates); if (runConfiguration instanceof FusAwareRunConfiguration) { - List> additionalData = ((FusAwareRunConfiguration)runConfiguration).getAdditionalUsageData(); + List> additionalData = SlowOperations.allowSlowOperations( + () -> ((FusAwareRunConfiguration)runConfiguration).getAdditionalUsageData() + ); pairs.add(ADDITIONAL_FIELD.with(new ObjectEventData(additionalData))); } if (runConfiguration instanceof TargetEnvironmentAwareRunProfile) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeProcessor.java b/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeProcessor.java index 48a5153a71ab..9513759da1f5 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeProcessor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeProcessor.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.actions; @@ -20,6 +20,7 @@ import com.intellij.psi.*; import com.intellij.psi.codeStyle.ChangedRangesInfo; import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -105,7 +106,7 @@ public class ReformatCodeProcessor extends AbstractLayoutCodeProcessor { : document.getImmutableCharSequence(); try { - EditorScrollingPositionKeeper.perform(document, true, () -> { + EditorScrollingPositionKeeper.perform(document, true, () -> SlowOperations.allowSlowOperations(() -> { if (processChangedTextOnly) { ChangedRangesInfo info = VcsFacade.getInstance().getChangedRangesInfo(fileToProcess); if (info != null) { @@ -117,7 +118,7 @@ public class ReformatCodeProcessor extends AbstractLayoutCodeProcessor { Collection ranges = getRangesToFormat(fileToProcess); CodeStyleManager.getInstance(myProject).reformatText(fileToProcess, ranges); } - }); + })); } catch (ProcessCanceledException pce) { if (before != null) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowAutoImportPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowAutoImportPass.java index 8cf8bfa36013..76eaa1fa1e82 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowAutoImportPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowAutoImportPass.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.daemon.impl; @@ -36,6 +36,7 @@ import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.registry.Registry; import com.intellij.psi.*; import com.intellij.psi.util.PsiUtilCore; +import com.intellij.util.SlowOperations; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -85,6 +86,10 @@ public class ShowAutoImportPass extends TextEditorHighlightingPass { if (DumbService.isDumb(myProject) || !myFile.isValid()) return; if (myEditor.isDisposed() || myEditor instanceof EditorWindow && !((EditorWindow)myEditor).isValid()) return; + SlowOperations.allowSlowOperations(() -> doShowImports()); + } + + private void doShowImports() { int caretOffset = myEditor.getCaretModel().getOffset(); importUnambiguousImports(caretOffset); if (isImportHintEnabled()) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyHandler.java index 92fec3b63bc7..ccc6bd2559ef 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyHandler.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.editorActions; @@ -23,6 +23,7 @@ import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -97,7 +98,7 @@ public class CopyHandler extends EditorActionHandler implements CopyAction.Trans final List transferableDataList = new ArrayList<>(); - DumbService.getInstance(project).withAlternativeResolveEnabled(() -> { + DumbService.getInstance(project).withAlternativeResolveEnabled(() -> SlowOperations.allowSlowOperations(() -> { for (CopyPastePostProcessor processor : CopyPastePostProcessor.EP_NAME.getExtensionList()) { try { transferableDataList.addAll(processor.collectTransferableData(file, editor, startOffsets, endOffsets)); @@ -109,7 +110,7 @@ public class CopyHandler extends EditorActionHandler implements CopyAction.Trans LOG.error(e); } } - }); + })); String text = editor.getCaretModel().supportsMultipleCarets() ? EditorCopyPasteHelperImpl.getSelectedTextForClipboard(editor, transferableDataList) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java index d6d62aa1e739..45536819ef36 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.editorActions; import com.google.common.annotations.VisibleForTesting; @@ -32,6 +32,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.util.DocumentUtil; import com.intellij.util.IncorrectOperationException; import com.intellij.util.Producer; +import com.intellij.util.SlowOperations; import com.intellij.util.text.CharArrayUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -208,7 +209,9 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser final Ref indented = new Ref<>(Boolean.FALSE); for (Map.Entry> e : extraData.entrySet()) { //noinspection unchecked - e.getKey().processTransferableData(project, editor, bounds, caretOffset, indented, e.getValue()); + SlowOperations.allowSlowOperations( + () -> e.getKey().processTransferableData(project, editor, bounds, caretOffset, indented, e.getValue()) + ); } boolean pastedTextContainsWhiteSpacesOnly = diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java index 670543d8222a..652eb962cf84 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.editorActions; import com.intellij.codeInsight.AutoPopupController; @@ -47,6 +47,7 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import com.intellij.psi.util.PsiUtilBase; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.text.CharArrayUtil; import org.jetbrains.annotations.ApiStatus; @@ -142,6 +143,10 @@ public final class TypedHandler extends TypedActionHandlerBase { @Override public void execute(@NotNull final Editor originalEditor, final char charTyped, @NotNull final DataContext dataContext) { + SlowOperations.allowSlowOperations(()-> doExecute(originalEditor, charTyped, dataContext)); + } + + private void doExecute(@NotNull Editor originalEditor, char charTyped, @NotNull DataContext dataContext) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); final PsiFile originalFile; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java index 34fee2c27e1e..e4ab49175216 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.folding.impl; import com.intellij.lang.folding.FoldingDescriptor; @@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.SmartPointerManager; import com.intellij.util.ObjectUtils; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NotNull; @@ -255,7 +256,7 @@ final class UpdateFoldRegionsOperation implements Runnable { private boolean shouldRemoveRegion(@NotNull FoldRegion region, @NotNull EditorFoldingInfo info, @NotNull Map rangeToExpandStatusMap, @NotNull Ref matchingInfo) { matchingInfo.set(null); - PsiElement element = info.getPsiElement(region); + PsiElement element = SlowOperations.allowSlowOperations(() -> info.getPsiElement(region)); if (element != null) { PsiFile containingFile = element.getContainingFile(); boolean isInjected = InjectedLanguageManager.getInstance(myProject).isInjectedFragment(containingFile); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoComponent.java index 5578ea865bec..24db4b9ad844 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoComponent.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.hint; @@ -24,8 +24,8 @@ import com.intellij.ui.ColorUtil; import com.intellij.ui.JBColor; import com.intellij.ui.ScrollPaneFactory; import com.intellij.util.Function; +import com.intellij.util.SlowOperations; import com.intellij.util.indexing.DumbModeAccessType; -import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.accessibility.AccessibleContextUtil; @@ -319,6 +319,10 @@ public class ParameterInfoComponent extends JPanel { } ParameterInfoControllerBase.Model update(boolean singleParameterInfo) { + return SlowOperations.allowSlowOperations(() -> doUpdate(singleParameterInfo)); + } + + private ParameterInfoControllerBase.Model doUpdate(boolean singleParameterInfo) { MyParameterContext context = new MyParameterContext(singleParameterInfo); int highlightedComponentIdx = -1; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionActionWithTextCaching.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionActionWithTextCaching.java index 244cb4ba320e..66cc67fedef6 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionActionWithTextCaching.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionActionWithTextCaching.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.intention.impl; @@ -17,6 +17,7 @@ import com.intellij.openapi.util.NlsContexts; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -205,7 +206,7 @@ public class IntentionActionWithTextCaching implements Comparable myAction.invoke(project, editor, file)); myMarkInvoked.accept(IntentionActionWithTextCaching.this, myAction); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java index d230bc63f181..8a9c7185c553 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.intention.impl; @@ -46,6 +46,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.psi.stubs.StubTextInconsistencyException; import com.intellij.util.PairProcessor; +import com.intellij.util.SlowOperations; import com.intellij.util.ThreeState; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -264,7 +265,9 @@ public class ShowIntentionActionsHandler implements CodeInsightActionHandler { } PsiFile injectedFile = InjectedLanguageUtil.findInjectedPsiNoCommit(hostFile, hostEditor.getCaretModel().getOffset()); - return chooseBetweenHostAndInjected(hostFile, hostEditor, injectedFile, - (psiFile, editor) -> availableFor(psiFile, editor, action)); + return chooseBetweenHostAndInjected( + hostFile, hostEditor, injectedFile, + (psiFile, editor) -> SlowOperations.allowSlowOperations(() -> availableFor(psiFile, editor, action)) + ); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemAction.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemAction.java index c296553dfb76..2429beb6c7ac 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemAction.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.lookup.impl.actions; @@ -22,6 +22,7 @@ import com.intellij.openapi.editor.actionSystem.EditorActionHandler; import com.intellij.openapi.editor.actionSystem.LatencyAwareEditorAction; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -68,7 +69,7 @@ public abstract class ChooseItemAction extends EditorAction implements HintManag FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_FINISH_BY_CONTROL_DOT); } - lookup.finishLookup(finishingChar); + SlowOperations.allowSlowOperations(() -> lookup.finishLookup(finishingChar)); } @@ -116,8 +117,11 @@ public abstract class ChooseItemAction extends EditorAction implements HintManag return true; } - List templates = TemplateManagerImpl.listApplicableTemplateWithInsertingDummyIdentifier( - TemplateActionContext.expanding(file, editor)); + List templates = SlowOperations.allowSlowOperations( + () -> TemplateManagerImpl.listApplicableTemplateWithInsertingDummyIdentifier( + TemplateActionContext.expanding(file, editor) + ) + ); TemplateImpl template = LiveTemplateCompletionContributor.findFullMatchedApplicableTemplate(editor, offset, templates); if (template != null && shortcutChar == TemplateSettings.getInstance().getShortcutChar(template)) { return true; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewManager.java b/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewManager.java index c33311b16660..a2454cff091e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewManager.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.preview; import com.intellij.openapi.Disposable; @@ -19,6 +19,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.util.Alarm; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -161,7 +162,7 @@ final class ImageOrColorPreviewManager implements Disposable, EditorMouseMotionL if (elements == null && event.getMouseEvent().isShiftDown()) { alarm.addRequest(new PreviewRequest(editor, event.getOffset(), false), 100); } - else if (elements != null && !getPsiElementsAt(editor, event.getOffset()).equals(elements)) { + else if (elements != null && !SlowOperations.allowSlowOperations(() -> getPsiElementsAt(editor, event.getOffset()).equals(elements))) { myElements = null; for (ElementPreviewProvider provider : ElementPreviewProvider.EP_NAME.getExtensionList()) { try { @@ -189,6 +190,10 @@ final class ImageOrColorPreviewManager implements Disposable, EditorMouseMotionL @Override public void run() { + SlowOperations.allowSlowOperations(() -> doRun()); + } + + private void doRun() { Collection elements = getPsiElementsAt(editor, offset); if (elements.equals(myElements)) return; for (PsiElement element : elements) { diff --git a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java index db8797541c00..da30ac7e1daf 100644 --- a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java +++ b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.find.actions; import com.intellij.codeInsight.TargetElementUtil; @@ -63,10 +63,7 @@ import com.intellij.usageView.UsageViewUtil; import com.intellij.usages.*; import com.intellij.usages.impl.*; import com.intellij.usages.rules.UsageFilteringRuleProvider; -import com.intellij.util.ArrayUtil; -import com.intellij.util.BitUtil; -import com.intellij.util.Processor; -import com.intellij.util.SmartList; +import com.intellij.util.*; import com.intellij.util.concurrency.EdtScheduledExecutorService; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.ui.AsyncProcessIcon; @@ -197,10 +194,10 @@ public class ShowUsagesAction extends AnAction implements PopupAction, HintManag Editor editor = dataContext.getData(CommonDataKeys.EDITOR); RelativePoint popupPosition = JBPopupFactory.getInstance().guessBestPopupLocation(dataContext); SearchScope searchScope = FindUsagesOptions.findScopeByName(project, dataContext, FindSettings.getInstance().getDefaultScopeName()); - findShowUsages( + SlowOperations.allowSlowOperations(() -> findShowUsages( project, dataContext, targetVariants, FindBundle.message("show.usages.ambiguous.title"), createVariantHandler(project, editor, popupPosition, searchScope) - ); + )); } @NotNull diff --git a/platform/lang-impl/src/com/intellij/find/impl/FindPopupPanel.java b/platform/lang-impl/src/com/intellij/find/impl/FindPopupPanel.java index 77a68510068d..3bae3be0403e 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/FindPopupPanel.java +++ b/platform/lang-impl/src/com/intellij/find/impl/FindPopupPanel.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.find.impl; import com.intellij.CommonBundle; @@ -1909,7 +1909,7 @@ public class FindPopupPanel extends JBPanel implements FindUI { TextChunk[] text = usageAdapter.getPresentation().getText(); // line number / file info VirtualFile file = usageAdapter.getFile(); - String uniqueVirtualFilePath = getFilePath(usageAdapter); + String uniqueVirtualFilePath = SlowOperations.allowSlowOperations(() -> getFilePath(usageAdapter)); VirtualFile prevFile = findPrevFile(table, row, column); SimpleTextAttributes attributes = Comparing.equal(file, prevFile) ? REPEATED_FILE_ATTRIBUTES : ORDINAL_ATTRIBUTES; append(uniqueVirtualFilePath, attributes); diff --git a/platform/lang-impl/src/com/intellij/ide/actions/CreateFileFromTemplateDialog.java b/platform/lang-impl/src/com/intellij/ide/actions/CreateFileFromTemplateDialog.java index b2dc9cbb9ede..f22b0c3eb1f2 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/CreateFileFromTemplateDialog.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/CreateFileFromTemplateDialog.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.actions; @@ -22,6 +22,7 @@ import com.intellij.psi.SmartPointerManager; import com.intellij.psi.SmartPsiElementPointer; import com.intellij.util.Consumer; import com.intellij.util.PlatformIcons; +import com.intellij.util.SlowOperations; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -297,7 +298,7 @@ public class CreateFileFromTemplateDialog extends DialogWrapper { if (isValid && isExtraValid) { popup.closeOk(e); - T createdElement = (T) createElement(newElementName, elementCreator); + T createdElement = (T)SlowOperations.allowSlowOperations(() -> createElement(newElementName, elementCreator)); if (createdElement != null) { elementConsumer.consume(createdElement); } diff --git a/platform/lang-impl/src/com/intellij/ide/actions/CreateFromTemplateAction.java b/platform/lang-impl/src/com/intellij/ide/actions/CreateFromTemplateAction.java index db6d40d7d646..5fd6faf2c594 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/CreateFromTemplateAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/CreateFromTemplateAction.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.actions; import com.intellij.CommonBundle; @@ -19,6 +19,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiNameIdentifierOwner; +import com.intellij.util.SlowOperations; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -89,7 +90,9 @@ public abstract class CreateFromTemplateAction extends AnA if (offset != -1 && editor != null && !editor.isDisposed()) { editor.getCaretModel().moveToOffset(offset); } - postProcess(createdElement, selectedTemplateName.get(), builder.getCustomProperties()); + SlowOperations.allowSlowOperations( + () -> postProcess(createdElement, selectedTemplateName.get(), builder.getCustomProperties()) + ); } }); } diff --git a/platform/lang-impl/src/com/intellij/ide/impl/SelectInTargetPsiWrapper.java b/platform/lang-impl/src/com/intellij/ide/impl/SelectInTargetPsiWrapper.java index 2f8d3ae0bcf9..152e0035cd93 100644 --- a/platform/lang-impl/src/com/intellij/ide/impl/SelectInTargetPsiWrapper.java +++ b/platform/lang-impl/src/com/intellij/ide/impl/SelectInTargetPsiWrapper.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.impl; import com.intellij.ide.SelectInContext; @@ -22,6 +8,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.util.PsiUtilCore; +import com.intellij.util.SlowOperations; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -86,7 +73,7 @@ public abstract class SelectInTargetPsiWrapper implements SelectInTarget { if (original != null && !original.isValid()) { throw new PsiInvalidElementAccessException(original, "Returned by " + selector + " of " + selector.getClass()); } - select(original, requestFocus); + SlowOperations.allowSlowOperations(() -> select(original, requestFocus)); } else { select(selector, file, requestFocus); diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarModel.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarModel.java index 66f254b79320..c51834f1098a 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarModel.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarModel.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.navigationToolbar; @@ -18,10 +18,7 @@ import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; -import com.intellij.util.CommonProcessors; -import com.intellij.util.ObjectUtils; -import com.intellij.util.PairProcessor; -import com.intellij.util.Processor; +import com.intellij.util.*; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -90,6 +87,10 @@ public class NavBarModel { if (PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext) instanceof NavBarPanel) return; + SlowOperations.allowSlowOperations(() -> doUpdateModel(dataContext)); + } + + private void doUpdateModel(DataContext dataContext) { NavBarModelExtension ownerExtension = null; PsiElement psiElement = null; for (NavBarModelExtension extension : NavBarModelExtension.EP_NAME.getExtensionList()) { diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewNodeVisitor.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewNodeVisitor.java index e3b8ccf10de8..e9f487e9f01b 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewNodeVisitor.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewNodeVisitor.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.projectView.impl; import com.intellij.ide.projectView.ProjectViewNode; @@ -7,6 +7,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.ui.tree.AbstractTreeNodeVisitor; +import com.intellij.util.SlowOperations; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -54,6 +55,6 @@ class ProjectViewNodeVisitor extends AbstractTreeNodeVisitor { @Override protected boolean isAncestor(@NotNull PsiElement content, @NotNull PsiElement element) { - return PsiTreeUtil.isAncestor(content, element, true); + return SlowOperations.allowSlowOperations(() -> PsiTreeUtil.isAncestor(content, element, true)); } } diff --git a/platform/lang-impl/src/com/intellij/ide/util/PsiElementListCellRenderer.java b/platform/lang-impl/src/com/intellij/ide/util/PsiElementListCellRenderer.java index cb5f209d0401..0fc60e4bbce6 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/PsiElementListCellRenderer.java +++ b/platform/lang-impl/src/com/intellij/ide/util/PsiElementListCellRenderer.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.util; import com.intellij.ide.ui.UISettings; @@ -31,6 +31,7 @@ import com.intellij.ui.SimpleTextAttributes; import com.intellij.ui.speedSearch.SpeedSearchUtil; import com.intellij.util.IconUtil; import com.intellij.util.ObjectUtils; +import com.intellij.util.SlowOperations; import com.intellij.util.text.Matcher; import com.intellij.util.text.MatcherHolder; import com.intellij.util.ui.UIUtil; @@ -214,7 +215,9 @@ public abstract class PsiElementListCellRenderer extends J Component rightCellRendererComponent = null; JPanel spacer = null; if (rightRenderer != null) { - rightCellRendererComponent = rightRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + rightCellRendererComponent = SlowOperations.allowSlowOperations( + () -> rightRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus) + ); add(rightCellRendererComponent, BorderLayout.EAST); spacer = new JPanel(); spacer.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2)); @@ -224,7 +227,9 @@ public abstract class PsiElementListCellRenderer extends J } ListCellRenderer leftRenderer = new LeftRenderer(null, value == null ? new ItemMatchers(null, null) : getItemMatchers(list, value)); - final Component leftCellRendererComponent = leftRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + final Component leftCellRendererComponent = SlowOperations.allowSlowOperations( + () -> leftRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus) + ); add(leftCellRendererComponent, LEFT); final Color bg = isSelected ? UIUtil.getListSelectionBackground(true) : leftCellRendererComponent.getBackground(); setBackground(bg); diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java index 397d3de955e3..39eddc226d12 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.util.gotoByName; @@ -46,6 +46,7 @@ import com.intellij.ui.speedSearch.SpeedSearchUtil; import com.intellij.util.ArrayUtilRt; import com.intellij.util.Function; import com.intellij.util.ObjectUtils; +import com.intellij.util.SlowOperations; import com.intellij.util.concurrency.Semaphore; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.EmptyIcon; @@ -386,8 +387,8 @@ public final class GotoActionModel implements ChooseByNameModel, Comparator path, boolean showNonPopupGroups) { DataContext context = myProject == null ? DataContext.EMPTY_CONTEXT : SimpleDataContext.getProjectContext(myProject); - AnAction[] actions = group - .getChildren(AnActionEvent.createFromDataContext(ActionPlaces.ACTION_SEARCH, null, context)); + AnActionEvent event = AnActionEvent.createFromDataContext(ActionPlaces.ACTION_SEARCH, null, context); + AnAction[] actions = SlowOperations.allowSlowOperations(() -> group.getChildren(event)); boolean hasMeaningfulChildren = ContainerUtil.exists(actions, action -> myActionManager.getId(action) != null); if (!hasMeaningfulChildren) { diff --git a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserCombo.java b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserCombo.java index 6f70e3169ce0..b2032e3a560e 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserCombo.java +++ b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserCombo.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.util.scopeChooser; import com.intellij.ide.DataManager; @@ -22,6 +22,7 @@ import com.intellij.ui.TitledSeparator; import com.intellij.ui.scale.JBUIScale; import com.intellij.util.BitUtil; import com.intellij.util.Processor; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.JBEmptyBorder; import com.intellij.util.ui.UIUtil; @@ -179,7 +180,7 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Dispo }; for (SearchScopeProvider each : SearchScopeProvider.EP_NAME.getExtensions()) { if (StringUtil.isEmpty(each.getDisplayName())) continue; - List scopes = each.getSearchScopes(project, dataContext); + List scopes = SlowOperations.allowSlowOperations(() -> each.getSearchScopes(project, dataContext)); if (scopes.isEmpty()) continue; if (!processor.process(new ScopeSeparator(each.getDisplayName()))) return false; for (SearchScope scope : ContainerUtil.sorted(scopes, comparator)) { diff --git a/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/UniqueVFilePathBuilderImpl.java b/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/UniqueVFilePathBuilderImpl.java index 183234041e4f..93f527e21004 100644 --- a/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/UniqueVFilePathBuilderImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/UniqueVFilePathBuilderImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.fileEditor.impl; import com.intellij.ide.lightEdit.LightEdit; @@ -9,7 +9,6 @@ import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.ModificationTracker; -import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.UniqueNameBuilder; diff --git a/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java index 23abae1c2485..f397d573e0b7 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.refactoring; import com.intellij.codeInsight.actions.VcsFacade; @@ -61,6 +61,7 @@ import com.intellij.usages.impl.UnknownUsagesInUnloadedModules; import com.intellij.usages.impl.UsageViewImpl; import com.intellij.usages.rules.PsiElementUsage; import com.intellij.util.Processor; +import com.intellij.util.SlowOperations; import com.intellij.util.ThrowableRunnable; import com.intellij.util.containers.MultiMap; import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; @@ -627,10 +628,10 @@ public abstract class BaseRefactoringProcessor implements Runnable { @Override public final void run() { - Runnable runnable = this::doRun; - if (shouldDisableAccessChecks()) { - runnable = () -> NonProjectFileWritingAccessProvider.disableChecksDuring(this::doRun); - } + Runnable baseRunnable = () -> SlowOperations.allowSlowOperations(this::doRun); + Runnable runnable = shouldDisableAccessChecks() ? + () -> NonProjectFileWritingAccessProvider.disableChecksDuring(baseRunnable) : + baseRunnable; if (ApplicationManager.getApplication().isUnitTestMode()) { ApplicationManager.getApplication().assertIsWriteThread(); runnable.run(); diff --git a/platform/lang-impl/src/com/intellij/refactoring/actions/BaseRefactoringAction.java b/platform/lang-impl/src/com/intellij/refactoring/actions/BaseRefactoringAction.java index a1dd76a74056..c1570581d5c1 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/actions/BaseRefactoringAction.java +++ b/platform/lang-impl/src/com/intellij/refactoring/actions/BaseRefactoringAction.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.refactoring.actions; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; @@ -27,6 +27,7 @@ import com.intellij.refactoring.RefactoringActionHandler; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.rename.inplace.InplaceRefactoring; import com.intellij.refactoring.util.CommonRefactoringUtil; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -105,7 +106,7 @@ public abstract class BaseRefactoringAction extends AnAction implements UpdateIn } IdeEventQueue.getInstance().setEventCount(eventCount); - performRefactoringAction(project, dataContext, handler); + SlowOperations.allowSlowOperations(() -> performRefactoringAction(project, dataContext, handler)); } @ApiStatus.Internal diff --git a/platform/lang-impl/src/com/intellij/refactoring/actions/RenameElementAction.java b/platform/lang-impl/src/com/intellij/refactoring/actions/RenameElementAction.java index e45b2782e6aa..85d27f1c2119 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/actions/RenameElementAction.java +++ b/platform/lang-impl/src/com/intellij/refactoring/actions/RenameElementAction.java @@ -13,6 +13,7 @@ import com.intellij.refactoring.rename.PsiElementRenameHandler; import com.intellij.refactoring.rename.Renamer; import com.intellij.refactoring.rename.RenamerFactory; import com.intellij.refactoring.util.CommonRefactoringUtil; +import com.intellij.util.SlowOperations; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -36,7 +37,7 @@ public class RenameElementAction extends AnAction implements UpdateInBackground @ApiStatus.Internal public boolean isAvailable(@NotNull DataContext dataContext) { return dataContext.getData(CommonDataKeys.PROJECT) != null - && getAvailableRenamers(dataContext).findAny().isPresent(); + && SlowOperations.allowSlowOperations(() -> getAvailableRenamers(dataContext).findAny().isPresent()); } @Override @@ -51,7 +52,7 @@ public class RenameElementAction extends AnAction implements UpdateInBackground return; } - List renamers = getAvailableRenamers(dataContext).collect(Collectors.toList()); + List renamers = SlowOperations.allowSlowOperations(() -> getAvailableRenamers(dataContext).collect(Collectors.toList())); if (renamers.isEmpty()) { String message = RefactoringBundle.getCannotRefactorMessage( RefactoringBundle.message("error.wrong.caret.position.symbol.to.refactor") diff --git a/platform/lang-impl/src/com/intellij/refactoring/move/MoveHandler.java b/platform/lang-impl/src/com/intellij/refactoring/move/MoveHandler.java index 9d53ace860b3..486ccbcc4ac6 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/move/MoveHandler.java +++ b/platform/lang-impl/src/com/intellij/refactoring/move/MoveHandler.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.refactoring.move; @@ -21,6 +21,7 @@ import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.actions.BaseRefactoringAction; import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesUtil; import com.intellij.refactoring.util.CommonRefactoringUtil; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -132,13 +133,15 @@ public class MoveHandler implements RefactoringActionHandler { public static void doMove(Project project, PsiElement @NotNull [] elements, PsiElement targetContainer, DataContext dataContext, MoveCallback callback) { if (elements.length == 0) return; - for (MoveHandlerDelegate delegate: MoveHandlerDelegate.EP_NAME.getExtensionList()) { - if (delegate.canMove(elements, targetContainer, null)) { - logDelegate(project, delegate, elements[0].getLanguage()); - delegate.doMove(project, elements, delegate.adjustTargetForMove(dataContext, targetContainer), callback); - break; + SlowOperations.allowSlowOperations(() -> { + for (MoveHandlerDelegate delegate : MoveHandlerDelegate.EP_NAME.getExtensionList()) { + if (delegate.canMove(elements, targetContainer, null)) { + logDelegate(project, delegate, elements[0].getLanguage()); + delegate.doMove(project, elements, delegate.adjustTargetForMove(dataContext, targetContainer), callback); + break; + } } - } + }); } /** diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandler2Renamer.java b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandler2Renamer.java index 8e937c00d681..b61bcec1d91b 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandler2Renamer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandler2Renamer.java @@ -1,10 +1,11 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.refactoring.rename; import com.intellij.ide.IdeEventQueue; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.project.Project; import com.intellij.refactoring.actions.BaseRefactoringAction; +import com.intellij.util.SlowOperations; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -32,7 +33,9 @@ final class RenameHandler2Renamer implements Renamer { @Override public void performRename() { - IdeEventQueue.getInstance().setEventCount(myEventCount); // Make DataContext valid again. - BaseRefactoringAction.performRefactoringAction(myProject, myDataContext, myHandler); + SlowOperations.allowSlowOperations(() -> { + IdeEventQueue.getInstance().setEventCount(myEventCount); // Make DataContext valid again. + BaseRefactoringAction.performRefactoringAction(myProject, myDataContext, myHandler); + }); } } diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/MemberInplaceRenamer.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/MemberInplaceRenamer.java index 8a4e66b45d68..36672a888a2d 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/MemberInplaceRenamer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/MemberInplaceRenamer.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.refactoring.rename.inplace; import com.intellij.codeInsight.TargetElementUtil; @@ -38,6 +38,7 @@ import com.intellij.refactoring.rename.RenameUtil; import com.intellij.refactoring.rename.naming.AutomaticRenamerFactory; import com.intellij.refactoring.util.TextOccurrencesUtil; import com.intellij.usageView.UsageViewUtil; +import com.intellij.util.SlowOperations; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -223,7 +224,7 @@ public class MemberInplaceRenamer extends VariableInplaceRenamer { return; } - Runnable performRunnable = () -> { + Runnable performRunnable = () -> SlowOperations.allowSlowOperations(() -> { if (DumbService.isDumb(myProject)) { DumbService.getInstance(myProject).showDumbModeNotification(RefactoringBundle.message("refactoring.not.available.indexing")); return; @@ -236,7 +237,7 @@ public class MemberInplaceRenamer extends VariableInplaceRenamer { performRenameInner(substituted, newName); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); }, commandName, null); - }; + }); if (ApplicationManager.getApplication().isUnitTestMode()) { performRunnable.run(); diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.java index 8b4509bd97c7..4b44c8695a47 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.actionSystem.ex; import com.intellij.ide.DataManager; @@ -22,6 +22,7 @@ import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.ComponentUtil; import com.intellij.util.ObjectUtils; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; @@ -166,10 +167,10 @@ public final class ActionUtil { try { if (beforeActionPerformed) { - action.beforeActionPerformedUpdate(e); + SlowOperations.allowSlowOperations(() -> action.beforeActionPerformedUpdate(e)); } else { - action.update(e); + SlowOperations.allowSlowOperations(() -> action.update(e)); } presentation.putClientProperty(WOULD_BE_ENABLED_IF_NOT_DUMB_MODE, !allowed && presentation.isEnabled()); presentation.putClientProperty(WOULD_BE_VISIBLE_IF_NOT_DUMB_MODE, !allowed && presentation.isVisible()); @@ -265,7 +266,7 @@ public final class ActionUtil { public static void performActionDumbAware(AnAction action, AnActionEvent e) { try { - action.actionPerformed(e); + SlowOperations.allowSlowOperations(() -> action.actionPerformed(e)); } catch (IndexNotReadyException ex) { LOG.info(ex); diff --git a/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java b/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java index c6193094bcfb..66d35e116291 100644 --- a/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java +++ b/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java @@ -1,19 +1,16 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ui.treeStructure; import com.intellij.ide.IdeBundle; import com.intellij.ide.util.treeView.*; import com.intellij.openapi.ui.GraphicsConfig; import com.intellij.openapi.ui.Queryable; -import com.intellij.openapi.util.Condition; -import com.intellij.openapi.util.Conditions; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.*; import com.intellij.openapi.util.registry.Registry; import com.intellij.ui.*; import com.intellij.ui.tree.TreePathBackgroundSupplier; import com.intellij.util.ArrayUtil; +import com.intellij.util.SlowOperations; import com.intellij.util.ThreeState; import com.intellij.util.ui.*; import com.intellij.util.ui.tree.TreeUtil; @@ -330,7 +327,7 @@ public class Tree extends JTree implements ComponentWithEmptyText, ComponentWith for (int row = firstVisibleRow; row <= lastVisibleRow; row++) { TreePath path = getPathForRow(row); - Color color = path == null ? null : getFileColorForPath(path); + Color color = path == null ? null : SlowOperations.allowSlowOperations(() -> getFileColorForPath(path)); if (color != null) { Rectangle bounds = getRowBounds(row); g.setColor(color); diff --git a/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java b/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java index dd1878f50ae9..2d46c7f7b236 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.actions; import com.intellij.featureStatistics.FeatureUsageTracker; @@ -1476,7 +1476,9 @@ public final class Switcher extends AnAction implements DumbAware { @NlsSafe String getNameForRendering() { if (myNameForRendering == null) { // Recently changed files would also be taken into account (not only open 'visible' files) - myNameForRendering = EditorTabPresentationUtil.getUniqueEditorTabTitle(myProject, first, second); + myNameForRendering = SlowOperations.allowSlowOperations( + () -> EditorTabPresentationUtil.getUniqueEditorTabTitle(myProject, first, second) + ); } return myNameForRendering; } diff --git a/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java b/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java index 4f517840e220..4ebecd460138 100644 --- a/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.startup.impl; import com.intellij.diagnostic.*; @@ -34,6 +34,7 @@ import com.intellij.openapi.startup.StartupActivity; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.registry.Registry; import com.intellij.ui.GuiUtils; +import com.intellij.util.SlowOperations; import com.intellij.util.TimeoutUtil; import com.intellij.util.concurrency.AppExecutorUtil; import org.intellij.lang.annotations.MagicConstant; @@ -238,7 +239,9 @@ public class StartupManagerImpl extends StartupManagerEx { counter.incrementAndGet(); dumbService.unsafeRunWhenSmart(() -> { - runActivity(uiFreezeWarned, extension, pluginDescriptor, ProgressIndicatorProvider.getGlobalProgressIndicator()); + SlowOperations.allowSlowOperations( + () -> runActivity(uiFreezeWarned, extension, pluginDescriptor, ProgressIndicatorProvider.getGlobalProgressIndicator()) + ); dumbUnawarePostActivitiesPassed(edtActivity, counter.decrementAndGet()); }); }); diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ToolbarUpdater.java b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ToolbarUpdater.java index 547806b99f99..2e3e10270a52 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ToolbarUpdater.java +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ToolbarUpdater.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.actionSystem.impl; import com.intellij.openapi.actionSystem.TimerListener; diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorTabbedContainer.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorTabbedContainer.java index 9b75bdf85b11..bed63191423e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorTabbedContainer.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorTabbedContainer.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.fileEditor.impl; import com.intellij.ide.DataManager; @@ -41,6 +41,7 @@ import com.intellij.ui.tabs.*; import com.intellij.ui.tabs.impl.*; import com.intellij.ui.tabs.impl.tabsLayout.TabsLayoutInfo; import com.intellij.ui.tabs.impl.tabsLayout.TabsLayoutSettingsManager; +import com.intellij.util.SlowOperations; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.TimedDeadzone; import com.intellij.util.ui.UIUtil; @@ -267,7 +268,7 @@ public final class EditorTabbedContainer implements CloseAction.CloseTarget { } tab = new TabInfo(component) - .setText(EditorTabPresentationUtil.getEditorTabTitle(myProject, file, myWindow)) + .setText(SlowOperations.allowSlowOperations(() -> EditorTabPresentationUtil.getEditorTabTitle(myProject, file, myWindow))) .setTabColor(EditorTabPresentationUtil.getEditorTabBackgroundColor(myProject, file, myWindow)) .setIcon(UISettings.getInstance().getShowFileIconInTabs() ? icon : null) .setTooltipText(tooltip) diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorWindow.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorWindow.java index bf635a39248e..361162043169 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorWindow.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorWindow.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.fileEditor.impl; import com.intellij.icons.AllIcons; @@ -33,6 +33,7 @@ import com.intellij.ui.tabs.impl.JBTabsImpl; import com.intellij.ui.tabs.impl.tabsLayout.TabsLayoutInfo; import com.intellij.util.IconUtil; import com.intellij.util.ObjectUtils; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.JBIterable; import com.intellij.util.containers.Stack; @@ -764,7 +765,9 @@ public final class EditorWindow { void updateFileName(@NotNull VirtualFile file) { int index = findEditorIndex(findFileComposite(file)); if (index != -1) { - setTitleAt(index, EditorTabPresentationUtil.getEditorTabTitle(getManager().getProject(), file, this)); + setTitleAt(index, SlowOperations.allowSlowOperations( + () -> EditorTabPresentationUtil.getEditorTabTitle(getManager().getProject(), file, this) + )); setToolTipTextAt(index, UISettings.getInstance().getShowTabsTooltips() ? getManager().getFileTooltipText(file) : null); diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorsSplitters.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorsSplitters.java index dd0a23990d10..f1f6daed3d72 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorsSplitters.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorsSplitters.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.fileEditor.impl; import com.intellij.diagnostic.Activity; @@ -37,16 +37,16 @@ import com.intellij.openapi.wm.ex.IdeFrameEx; import com.intellij.openapi.wm.ex.WindowManagerEx; import com.intellij.openapi.wm.impl.*; import com.intellij.testFramework.LightVirtualFileBase; -import com.intellij.ui.*; +import com.intellij.ui.ComponentUtil; +import com.intellij.ui.DirtyUI; +import com.intellij.ui.JBColor; +import com.intellij.ui.OnePixelSplitter; import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.docking.DockManager; import com.intellij.ui.tabs.JBTabs; import com.intellij.ui.tabs.impl.JBTabsImpl; import com.intellij.ui.tabs.impl.tabsLayout.TabsLayoutInfo; -import com.intellij.util.Alarm; -import com.intellij.util.IconUtil; -import com.intellij.util.ObjectUtils; -import com.intellij.util.PathUtil; +import com.intellij.util.*; import com.intellij.util.concurrency.NonUrgentExecutor; import com.intellij.util.containers.ArrayListSet; import com.intellij.util.containers.ContainerUtil; @@ -483,7 +483,7 @@ public class EditorsSplitters extends IdePanePanel implements UISettingsListener } catch (InvalidPathException ignored) { } - fileTitle = FrameTitleBuilder.getInstance().getFileTitle(project, file); + fileTitle = SlowOperations.allowSlowOperations(() -> FrameTitleBuilder.getInstance().getFileTitle(project, file)); } frame.setFileTitle(fileTitle, ioFile); } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorProviderManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorProviderManagerImpl.java index 3cc3b3b30625..efc705611d8d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorProviderManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileEditorProviderManagerImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.fileEditor.impl; import com.intellij.diagnostic.PluginException; @@ -16,6 +16,7 @@ import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.SlowOperations; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.xmlb.annotations.MapAnnotation; import org.jetbrains.annotations.NotNull; @@ -41,12 +42,12 @@ public final class FileEditorProviderManagerImpl extends FileEditorProviderManag List sharedProviders = new ArrayList<>(); boolean hideDefaultEditor = false; for (final FileEditorProvider provider : FileEditorProvider.EP_FILE_EDITOR_PROVIDER.getExtensionList()) { - if (ReadAction.compute(() -> { + if (SlowOperations.allowSlowOperations(() -> ReadAction.compute(() -> { if (DumbService.isDumb(project) && !DumbService.isDumbAware(provider)) { return false; } return provider.accept(project, file); - })) { + }))) { sharedProviders.add(provider); hideDefaultEditor |= provider.getPolicy() == FileEditorPolicy.HIDE_DEFAULT_EDITOR; if (provider.getPolicy() == FileEditorPolicy.HIDE_DEFAULT_EDITOR && !DumbService.isDumbAware(provider)) { diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestStackTraceParser.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestStackTraceParser.java index 7d325ac54e91..f0bb1a085523 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestStackTraceParser.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestStackTraceParser.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.testframework.sm.runner.ui; import com.intellij.execution.Location; @@ -6,6 +6,7 @@ import com.intellij.execution.testframework.sm.runner.SMTestLocator; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.util.SlowOperations; import java.io.BufferedReader; import java.io.IOException; @@ -59,7 +60,8 @@ public class TestStackTraceParser { myErrorMessage = line; } if (myTopLocationLine == null) { - List location = locator.getLocation(line, project, scope); + String finalLine = line; + List location = SlowOperations.allowSlowOperations(() -> locator.getLocation(finalLine, project, scope)); if (!location.isEmpty()) { myTopLocationLine = line; } diff --git a/platform/usageView/src/com/intellij/usages/impl/UsageViewTreeCellRenderer.java b/platform/usageView/src/com/intellij/usages/impl/UsageViewTreeCellRenderer.java index 8a26b8b08f0a..2f8c36d00a59 100644 --- a/platform/usageView/src/com/intellij/usages/impl/UsageViewTreeCellRenderer.java +++ b/platform/usageView/src/com/intellij/usages/impl/UsageViewTreeCellRenderer.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.usages.impl; import com.intellij.icons.AllIcons; @@ -7,7 +7,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.util.NlsContexts; import com.intellij.openapi.util.TextRange; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.FileStatus; import com.intellij.ui.ColoredTreeCellRenderer; import com.intellij.ui.DarculaColors; @@ -22,6 +21,7 @@ import com.intellij.usages.UsageGroup; import com.intellij.usages.UsageTarget; import com.intellij.usages.UsageViewPresentation; import com.intellij.util.FontUtil; +import com.intellij.util.SlowOperations; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.StartupUiUtil; import org.jetbrains.annotations.NotNull; @@ -65,6 +65,10 @@ final class UsageViewTreeCellRenderer extends ColoredTreeCellRenderer { return; } + SlowOperations.allowSlowOperations(() -> doCustomizeCellRenderer(tree, value, expanded, row)); + } + + private void doCustomizeCellRenderer(@NotNull JTree tree, Object value, boolean expanded, int row) { boolean showAsReadOnly = false; if (value instanceof Node && value != tree.getModel().getRoot()) { Node node = (Node)value; diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java index 5eabf77b4c91..677d7ecb4b22 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.xdebugger.impl.breakpoints; import com.intellij.configurationStore.XmlSerializer; @@ -15,6 +15,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.ex.http.HttpFileSystem; import com.intellij.util.Consumer; import com.intellij.util.EventDispatcher; +import com.intellij.util.SlowOperations; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; @@ -118,7 +119,7 @@ public final class XBreakpointManagerImpl implements XBreakpointManager { private void updateBreakpointInFile(final VirtualFile file) { ApplicationManager.getApplication().invokeLater(() -> { for (XBreakpointBase breakpoint : getAllBreakpoints()) { - XSourcePosition position = breakpoint.getSourcePosition(); + XSourcePosition position = SlowOperations.allowSlowOperations(() -> breakpoint.getSourcePosition()); if (position != null && Comparing.equal(position.getFile(), file)) { fireBreakpointChanged(breakpoint); } diff --git a/plugins/devkit/devkit-core/src/dom/ide/PluginDescriptorDomFileSearchScopeProvider.java b/plugins/devkit/devkit-core/src/dom/ide/PluginDescriptorDomFileSearchScopeProvider.java index 92074088ee87..937058658ec7 100644 --- a/plugins/devkit/devkit-core/src/dom/ide/PluginDescriptorDomFileSearchScopeProvider.java +++ b/plugins/devkit/devkit-core/src/dom/ide/PluginDescriptorDomFileSearchScopeProvider.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.idea.devkit.dom.ide; import com.intellij.icons.AllIcons; @@ -7,6 +7,7 @@ import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.search.*; +import com.intellij.util.SlowOperations; import com.intellij.util.xml.DomService; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -32,8 +33,9 @@ public class PluginDescriptorDomFileSearchScopeProvider implements SearchScopePr public List getSearchScopes(@NotNull Project project, @NotNull DataContext dataContext) { if (DumbService.isDumb(project) || !PsiUtil.isIdeaProject(project)) return Collections.emptyList(); - final Collection pluginDescriptorFiles = - DomService.getInstance().getDomFileCandidates(IdeaPlugin.class, GlobalSearchScopesCore.projectProductionScope(project)); + final Collection pluginDescriptorFiles = SlowOperations.allowSlowOperations( + () -> DomService.getInstance().getDomFileCandidates(IdeaPlugin.class, GlobalSearchScopesCore.projectProductionScope(project)) + ); GlobalSearchScope scope = GlobalSearchScope.filesScope(project, pluginDescriptorFiles); return Collections.singletonList(new DelegatingGlobalSearchScope(scope) { @NotNull