From 81cb35ff7a83af9f5ebcd408ae27cea2126939bb Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 28 Apr 2011 21:44:08 +0200 Subject: [PATCH] do not load inspection tools in AWT thread (cherry picked from commit 07dbd17181bdf9bcc0ec6baba0ad0c5d5b222967) --- .../impl/LocalInspectionsPassFactory.java | 6 +++-- .../WholeFileLocalInspectionsPassFactory.java | 6 ++++- .../InspectionProjectProfileManager.java | 22 +++++++++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java index 5258b42db531..528c32e34565 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java @@ -26,6 +26,7 @@ import com.intellij.openapi.components.AbstractProjectComponent; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; +import com.intellij.profile.codeInspection.InspectionProjectProfileManager; import com.intellij.psi.PsiFile; import com.intellij.util.PlatformUtils; import org.jetbrains.annotations.NonNls; @@ -59,8 +60,9 @@ public class LocalInspectionsPassFactory extends AbstractProjectComponent implem @Nullable public TextEditorHighlightingPass createHighlightingPass(@NotNull PsiFile file, @NotNull final Editor editor) { TextRange textRange = calculateRangeToProcess(editor); - if (textRange == null) return new ProgressableTextEditorHighlightingPass.EmptyPass(myProject, editor.getDocument() - ); + if (textRange == null || !InspectionProjectProfileManager.getInstance(file.getProject()).isProfileLoaded()){ + return new ProgressableTextEditorHighlightingPass.EmptyPass(myProject, editor.getDocument()); + } TextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor); return new LocalInspectionsPass(file, editor.getDocument(), textRange.getStartOffset(), textRange.getEndOffset(), visibleRange, true){ List getInspectionTools(InspectionProfileWrapper profile) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/WholeFileLocalInspectionsPassFactory.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/WholeFileLocalInspectionsPassFactory.java index 2216b24dcbcf..0c3555b409ef 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/WholeFileLocalInspectionsPassFactory.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/WholeFileLocalInspectionsPassFactory.java @@ -89,7 +89,11 @@ public class WholeFileLocalInspectionsPassFactory extends AbstractProjectCompone @Nullable public TextEditorHighlightingPass createHighlightingPass(@NotNull final PsiFile file, @NotNull final Editor editor) { TextRange textRange = FileStatusMap.getDirtyTextRange(editor, Pass.LOCAL_INSPECTIONS); - if (textRange == null || myFileTools.containsKey(file) && !myFileTools.get(file)) return null; + if (textRange == null || + !InspectionProjectProfileManager.getInstance(file.getProject()).isProfileLoaded() || + myFileTools.containsKey(file) && !myFileTools.get(file)) { + return null; + } return new LocalInspectionsPass(file, editor.getDocument(), 0, file.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true) { List getInspectionTools(InspectionProfileWrapper profile) { List tools = super.getInspectionTools(profile); diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManager.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManager.java index a41e807bbba8..7402fe037efa 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManager.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManager.java @@ -15,6 +15,7 @@ */ package com.intellij.profile.codeInspection; +import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.codeInsight.daemon.impl.SeverityRegistrar; import com.intellij.codeInsight.daemon.impl.analysis.HighlightingSettingsPerFile; import com.intellij.codeInspection.InspectionProfile; @@ -23,6 +24,7 @@ import com.intellij.codeInspection.ex.InspectionProfileWrapper; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.*; +import com.intellij.openapi.project.DumbAwareRunnable; import com.intellij.openapi.project.Project; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.InvalidDataException; @@ -37,11 +39,12 @@ import com.intellij.psi.PsiElement; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; /** * User: anna @@ -58,7 +61,7 @@ import java.util.Set; } ) public class InspectionProjectProfileManager extends DefaultProjectProfileManager implements SeverityProvider, ProjectComponent, PersistentStateComponent { - private final Map myName2Profile = new HashMap(); + private final Map myName2Profile = new ConcurrentHashMap(); private final SeverityRegistrar mySeverityRegistrar; private TogglePopupHintsPanel myTogglePopupHintsPanel; @@ -107,7 +110,11 @@ public class InspectionProjectProfileManager extends DefaultProjectProfileManage return getInspectionProfile(); } - @NotNull + public boolean isProfileLoaded() { + return myName2Profile.containsKey(getInspectionProfile().getName()); + } + + @Nullable public InspectionProfileWrapper getProfileWrapper(){ final InspectionProfile profile = getInspectionProfile(); final String profileName = profile.getName(); @@ -149,7 +156,7 @@ public class InspectionProjectProfileManager extends DefaultProjectProfileManage StatusBarEx statusBar = (StatusBarEx)WindowManager.getInstance().getStatusBar(myProject); myTogglePopupHintsPanel = new TogglePopupHintsPanel(myProject); statusBar.addWidget(myTogglePopupHintsPanel, myProject); - StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() { + StartupManager.getInstance(myProject).registerPostStartupActivity(new DumbAwareRunnable() { public void run() { final Set profiles = new HashSet(); profiles.add(getProjectProfileImpl()); @@ -161,6 +168,13 @@ public class InspectionProjectProfileManager extends DefaultProjectProfileManage for (Profile profile : profiles) { initProfileWrapper(profile); } + //restart daemon when profiles are ready + ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override + public void run() { + DaemonCodeAnalyzer.getInstance(myProject).restart(); + } + }); } }; if (app.isUnitTestMode() || app.isHeadlessEnvironment()) {