cleanup EditorNotifications clients

don't schedule updates on dumb mode changes when they will be done anyway
don't check for dumb in dumb-unaware providers
update on root change in a single place, not in thousand listeners
and other minor things
This commit is contained in:
peter
2019-01-31 15:21:37 +01:00
parent c0ad6d8b02
commit 0ef47ea190
8 changed files with 23 additions and 53 deletions
@@ -1,7 +1,6 @@
// 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.
package com.intellij.codeInsight.daemon.impl;
import com.intellij.ProjectTopics;
import com.intellij.codeEditor.JavaEditorFileSwapper;
import com.intellij.codeInsight.AttachSourcesProvider;
import com.intellij.ide.highlighter.JavaClassFileType;
@@ -18,7 +17,10 @@ import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.projectRoots.JavaSdkVersion;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.LibraryOrderEntry;
import com.intellij.openapi.roots.OrderEntry;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.LibrarySourceRootDetectorUtil;
import com.intellij.openapi.ui.Messages;
@@ -59,14 +61,14 @@ public class AttachSourcesNotificationProvider extends EditorNotifications.Provi
private final Project myProject;
@Deprecated // todo remove when Scala removes its usage
public AttachSourcesNotificationProvider(Project project, final EditorNotifications notifications) {
myProject = project;
myProject.getMessageBus().connect(project).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
@Override
public void rootsChanged(@NotNull ModuleRootEvent event) {
notifications.updateAllNotifications();
}
});
}
@SuppressWarnings("unused")
public AttachSourcesNotificationProvider(Project project) {
myProject = project;
}
@NotNull
@@ -1,7 +1,6 @@
// 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.
package com.intellij.codeInsight.daemon.impl
import com.intellij.ProjectTopics
import com.intellij.diff.DiffContentFactory
import com.intellij.diff.DiffManager
import com.intellij.diff.requests.SimpleDiffRequest
@@ -10,8 +9,6 @@ import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.fileTypes.LanguageFileType
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectBundle
import com.intellij.openapi.roots.ModuleRootEvent
import com.intellij.openapi.roots.ModuleRootListener
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.Key
import com.intellij.openapi.vfs.VirtualFile
@@ -22,8 +19,7 @@ import com.intellij.ui.EditorNotificationPanel
import com.intellij.ui.EditorNotifications
import com.intellij.ui.LightColors
class LibrarySourceNotificationProvider(private val project: Project, notifications: EditorNotifications) :
EditorNotifications.Provider<EditorNotificationPanel>() {
class LibrarySourceNotificationProvider(private val project: Project) : EditorNotifications.Provider<EditorNotificationPanel>() {
private companion object {
private val KEY = Key.create<EditorNotificationPanel>("library.source.mismatch.panel")
@@ -35,12 +31,6 @@ class LibrarySourceNotificationProvider(private val project: Project, notificati
private const val CLASS = SHOW_NAME or SHOW_FQ_CLASS_NAMES or SHOW_EXTENDS_IMPLEMENTS or SHOW_RAW_TYPE
}
init {
project.messageBus.connect(project).subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener {
override fun rootsChanged(event: ModuleRootEvent) = notifications.updateAllNotifications()
})
}
override fun getKey(): Key<EditorNotificationPanel> = KEY
override fun createNotificationPanel(file: VirtualFile, fileEditor: FileEditor): EditorNotificationPanel? {
@@ -15,7 +15,6 @@ import com.intellij.psi.PsiFile;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
import com.intellij.ui.EditorNotificationPanel;
import com.intellij.ui.EditorNotifications;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -29,7 +28,6 @@ public abstract class SdkSetupNotificationTestBase extends JavaCodeInsightFixtur
super.setUp();
setProjectSdk(IdeaTestUtil.getMockJdk17());
new SdkSetupNotificationProvider(getProject(), EditorNotifications.getInstance(getProject()));
}
@Override
@@ -1,14 +1,11 @@
// 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.
package com.intellij.codeInsight.daemon.impl;
import com.intellij.ProjectTopics;
import com.intellij.codeInsight.daemon.ProjectSdkSetupValidator;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.roots.ModuleRootListener;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.EditorNotificationPanel;
@@ -23,14 +20,8 @@ public class SdkSetupNotificationProvider extends EditorNotifications.Provider<E
private final Project myProject;
public SdkSetupNotificationProvider(Project project, final EditorNotifications notifications) {
public SdkSetupNotificationProvider(Project project) {
myProject = project;
myProject.getMessageBus().connect(project).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
@Override
public void rootsChanged(@NotNull ModuleRootEvent event) {
notifications.updateAllNotifications();
}
});
}
@NotNull
@@ -26,7 +26,6 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.ui.EditorNotifications;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -71,7 +70,6 @@ public class PsiAwareTextEditorImpl extends TextEditorImpl {
if (psiFile != null && psiFile.isValid()) {
DaemonCodeAnalyzer.getInstance(myProject).restart(psiFile);
}
EditorNotifications.getInstance(myProject).updateNotifications(myFile);
};
}
@@ -1,6 +1,7 @@
// 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.
package com.intellij.ui;
import com.intellij.ProjectTopics;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.fileEditor.FileEditor;
@@ -15,6 +16,8 @@ import com.intellij.openapi.progress.util.ProgressIndicatorUtils;
import com.intellij.openapi.progress.util.ReadTask;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.roots.ModuleRootListener;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
@@ -69,6 +72,12 @@ public class EditorNotificationsImpl extends EditorNotifications {
updateAllNotifications();
}
});
connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
@Override
public void rootsChanged(@NotNull ModuleRootEvent event) {
updateAllNotifications();
}
});
}
@Override
@@ -15,7 +15,6 @@
*/
package org.jetbrains.plugins.gradle.codeInsight;
import com.intellij.ProjectTopics;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.externalSystem.ExternalSystemModulePropertyManager;
import com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode;
@@ -27,8 +26,6 @@ import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.roots.ModuleRootListener;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
@@ -70,14 +67,8 @@ public class UseDistributionWithSourcesNotificationProvider extends EditorNotifi
GRADLE_SRC_DISTRIBUTION_PATTERN = Pattern.compile("https?\\\\?://services\\.gradle\\.org.*" + ALL_ZIP_DISTRIBUTION_URI_SUFFIX);
}
public UseDistributionWithSourcesNotificationProvider(Project project, final EditorNotifications notifications) {
public UseDistributionWithSourcesNotificationProvider(Project project) {
myProject = project;
project.getMessageBus().connect(project).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
@Override
public void rootsChanged(@NotNull ModuleRootEvent event) {
notifications.updateAllNotifications();
}
});
}
@NotNull
@@ -15,7 +15,6 @@
*/
package org.jetbrains.plugins.groovy.config;
import com.intellij.ProjectTopics;
import com.intellij.openapi.compiler.CompilerManager;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileTypes.FileType;
@@ -24,8 +23,6 @@ import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.roots.ModuleRootListener;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.text.StringUtil;
@@ -50,14 +47,8 @@ public class ConfigureGroovyLibraryNotificationProvider extends EditorNotificati
private final Set<FileType> supportedFileTypes;
public ConfigureGroovyLibraryNotificationProvider(Project project, final EditorNotifications notifications) {
public ConfigureGroovyLibraryNotificationProvider(Project project) {
myProject = project;
project.getMessageBus().connect(project).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
@Override
public void rootsChanged(@NotNull ModuleRootEvent event) {
notifications.updateAllNotifications();
}
});
supportedFileTypes = new HashSet<>();
supportedFileTypes.add(GroovyFileType.GROOVY_FILE_TYPE);