Don't highlight gradle scripts during gradle import.

Show warning on the top panel for these files
This commit is contained in:
Natalia Selezneva
2018-03-05 10:28:46 +03:00
parent 5f1118e820
commit 1f75eaed9a
@@ -236,6 +236,9 @@ class GradleScriptDefinitionsContributor(private val project: Project) : ScriptD
private class ErrorScriptDependenciesResolver(private val message: String? = null) : DependenciesResolver {
override fun resolve(scriptContents: ScriptContents, environment: Environment): ResolveResult {
if (ReloadGradleTemplatesOnSync.gradleState.isSyncInProgress) {
return ResolveResult.Failure(ScriptReport("Highlighting is impossible during Gradle Import", ScriptReport.Severity.WARNING))
}
return ResolveResult.Failure(
ScriptReport(
message ?: "Failed to load script definitions by ${GradleScriptDefinitionsContributor::class.java.name}"
@@ -245,10 +248,25 @@ class GradleScriptDefinitionsContributor(private val project: Project) : ScriptD
}
}
internal class GradleSyncState {
var isSyncInProgress: Boolean = false
}
class ReloadGradleTemplatesOnSync : ExternalSystemTaskNotificationListenerAdapter() {
companion object {
internal val gradleState = GradleSyncState()
}
override fun onStart(id: ExternalSystemTaskId, workingDir: String?) {
if (id.type == ExternalSystemTaskType.RESOLVE_PROJECT && id.projectSystemId == GRADLE_SYSTEM_ID) {
gradleState.isSyncInProgress = true
}
}
override fun onEnd(id: ExternalSystemTaskId) {
if (id.type == ExternalSystemTaskType.RESOLVE_PROJECT && id.projectSystemId == GRADLE_SYSTEM_ID) {
gradleState.isSyncInProgress = false
val project = id.findProject() ?: return
val gradleDefinitionsContributor = ScriptDefinitionContributor.find<GradleScriptDefinitionsContributor>(project)
gradleDefinitionsContributor?.reloadIfNeccessary()