diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 357797340a6..f9579e44fd5 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -2056,6 +2056,8 @@ + + diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinExternalSystemSyncListener.kt b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinExternalSystemSyncListener.kt new file mode 100644 index 00000000000..3de77cf68db --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinExternalSystemSyncListener.kt @@ -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() + } + } + } +} diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProvider.kt b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProvider.kt index 743c4dc12c1..bb8e2fe0354 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProvider.kt @@ -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) } diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinConfigurationCheckerComponent.kt b/idea/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinConfigurationCheckerComponent.kt index 189537a30a9..28557f6973d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinConfigurationCheckerComponent.kt +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinConfigurationCheckerComponent.kt @@ -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) } }