Don't show "Kotlin not configured" notifications while Gradle sync is running

#KT-15279 Fixed
This commit is contained in:
Dmitry Jemerov
2017-01-26 14:31:48 +01:00
parent ac35b182b5
commit c4032908c0
4 changed files with 71 additions and 4 deletions
+2
View File
@@ -2056,6 +2056,8 @@
<deadCode implementation="org.jetbrains.kotlin.idea.inspections.KotlinJUnitStaticEntryPoint"/>
<externalSystemTaskNotificationListener implementation="org.jetbrains.kotlin.idea.configuration.KotlinExternalSystemSyncListener"/>
<!--kotlin script specific extensions-->
<java.shortNamesCache implementation="org.jetbrains.kotlin.idea.core.script.dependencies.JavaClassesInScriptDependenciesShortNameCache"/>
<indexedRootsProvider implementation="org.jetbrains.kotlin.idea.core.script.dependencies.KotlinScriptDependenciesIndexableSetContributor"/>
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2017 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.
*/
package org.jetbrains.kotlin.idea.configuration
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType
import org.jetbrains.kotlin.idea.configuration.ui.KotlinConfigurationCheckerComponent
class KotlinExternalSystemSyncListener : ExternalSystemTaskNotificationListenerAdapter() {
override fun onStart(id: ExternalSystemTaskId) {
if (id.type == ExternalSystemTaskType.RESOLVE_PROJECT) {
id.findProject()?.let { project ->
KotlinConfigurationCheckerComponent.getInstance(project).syncStarted()
}
}
}
override fun onEnd(id: ExternalSystemTaskId) {
if (id.type == ExternalSystemTaskType.RESOLVE_PROJECT) {
id.findProject()?.let { project ->
KotlinConfigurationCheckerComponent.getInstance(project).syncDone()
}
}
}
}
@@ -39,6 +39,7 @@ import com.intellij.ui.EditorNotificationPanel
import com.intellij.ui.EditorNotifications
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.idea.configuration.ui.KotlinConfigurationCheckerComponent
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.idea.versions.UnsupportedAbiVersionNotificationPanelProvider
import org.jetbrains.kotlin.idea.versions.createComponentActionLabel
@@ -77,7 +78,8 @@ class KotlinSetupEnvironmentNotificationProvider(
return createSetupSdkPanel(myProject, psiFile)
}
if (!hasAnyKotlinRuntimeInScope(module) &&
if (!KotlinConfigurationCheckerComponent.getInstance(module.project).isSyncing &&
!hasAnyKotlinRuntimeInScope(module) &&
UnsupportedAbiVersionNotificationPanelProvider.collectBadRoots(module).isEmpty()) {
return createKotlinNotConfiguredPanel(module)
}
@@ -24,9 +24,10 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupManager
import org.jetbrains.kotlin.idea.configuration.*
import org.jetbrains.kotlin.idea.versions.*
import org.jetbrains.kotlin.idea.versions.VersionedLibrary
import java.util.concurrent.atomic.AtomicInteger
class KotlinConfigurationCheckerComponent protected constructor(project: Project) : AbstractProjectComponent(project) {
private var syncCount = AtomicInteger()
init {
NotificationsConfiguration.getNotificationsConfiguration().register(CONFIGURE_NOTIFICATION_GROUP_ID, NotificationDisplayType.STICKY_BALLOON, true)
@@ -41,13 +42,35 @@ class KotlinConfigurationCheckerComponent protected constructor(project: Project
if (!libraries.isEmpty()) {
notifyOutdatedKotlinRuntime(myProject, libraries)
}
showConfigureKotlinNotificationIfNeeded(myProject,
collectModulesWithOutdatedRuntime(libraries))
if (syncCount.get() == 0) {
showConfigureKotlinNotificationIfNeeded(myProject,
collectModulesWithOutdatedRuntime(libraries))
}
}
}
}
val isSyncing: Boolean get() = syncCount.get() > 0
fun syncStarted() {
syncCount.incrementAndGet()
}
fun syncDone() {
if (syncCount.decrementAndGet() == 0) {
DumbService.getInstance(myProject).smartInvokeLater {
if (!isSyncing) {
showConfigureKotlinNotificationIfNeeded(myProject,
collectModulesWithOutdatedRuntime(findOutdatedKotlinLibraries(myProject)))
}
}
}
}
companion object {
val CONFIGURE_NOTIFICATION_GROUP_ID = "Configure Kotlin in Project"
fun getInstance(project: Project): KotlinConfigurationCheckerComponent
= project.getComponent(KotlinConfigurationCheckerComponent::class.java)
}
}