Show notification that gradle project is needed to be imported to get code insight for kotlin scripts
This commit is contained in:
@@ -92,6 +92,11 @@ interface ScriptConfigurationManager {
|
||||
*/
|
||||
fun hasConfiguration(file: KtFile): Boolean
|
||||
|
||||
/**
|
||||
* returns true when there is no configuration and highlighting should be suspended
|
||||
*/
|
||||
fun isConfigurationLoadingInProgress(file: KtFile): Boolean
|
||||
|
||||
/**
|
||||
* See [ScriptConfigurationUpdater].
|
||||
*/
|
||||
|
||||
+1
-4
@@ -30,10 +30,7 @@ class ScriptTrafficLightRendererContributor : TrafficLightRendererContributor {
|
||||
if (!ScriptDefinitionsManager.getInstance(file.project).isReady()) {
|
||||
status.reasonWhySuspended = KotlinIdeaCoreBundle.message("text.loading.kotlin.script.definitions")
|
||||
status.errorAnalyzingFinished = false
|
||||
} else if (
|
||||
!ScriptConfigurationManager.getInstance(project).hasConfiguration(file)
|
||||
&& !ScriptConfigurationManager.isManualConfigurationLoading(file.originalFile.virtualFile)
|
||||
) {
|
||||
} else if (ScriptConfigurationManager.getInstance(project).isConfigurationLoadingInProgress(file)) {
|
||||
status.reasonWhySuspended = KotlinIdeaCoreBundle.message("text.loading.kotlin.script.configuration")
|
||||
status.errorAnalyzingFinished = false
|
||||
}
|
||||
|
||||
+3
@@ -55,6 +55,9 @@ class CompositeScriptConfigurationManager(val project: Project) : ScriptConfigur
|
||||
override fun hasConfiguration(file: KtFile): Boolean =
|
||||
getRelatedManager(file).hasCachedConfiguration(file)
|
||||
|
||||
override fun isConfigurationLoadingInProgress(file: KtFile): Boolean =
|
||||
getRelatedManager(file).isConfigurationLoadingInProgress(file)
|
||||
|
||||
override val updater: ScriptConfigurationUpdater
|
||||
get() = object : ScriptConfigurationUpdater {
|
||||
override fun ensureUpToDatedConfigurationSuggested(file: KtFile) =
|
||||
|
||||
+4
@@ -314,6 +314,10 @@ abstract class DefaultScriptingSupportBase(val project: Project) : ScriptingSupp
|
||||
override fun hasCachedConfiguration(file: KtFile): Boolean =
|
||||
getAppliedConfiguration(file.originalFile.virtualFile) != null
|
||||
|
||||
override fun isConfigurationLoadingInProgress(file: KtFile): Boolean {
|
||||
return !hasCachedConfiguration(file) && !ScriptConfigurationManager.isManualConfigurationLoading(file.originalFile.virtualFile)
|
||||
}
|
||||
|
||||
override fun getOrLoadConfiguration(
|
||||
virtualFile: VirtualFile,
|
||||
preloadedKtFile: KtFile?
|
||||
|
||||
+1
@@ -34,6 +34,7 @@ abstract class ScriptingSupport {
|
||||
|
||||
abstract fun clearCaches()
|
||||
abstract fun hasCachedConfiguration(file: KtFile): Boolean
|
||||
abstract fun isConfigurationLoadingInProgress(file: KtFile): Boolean
|
||||
abstract fun getOrLoadConfiguration(virtualFile: VirtualFile, preloadedKtFile: KtFile? = null): ScriptCompilationConfigurationWrapper?
|
||||
|
||||
abstract val updater: ScriptConfigurationUpdater
|
||||
|
||||
@@ -51,7 +51,9 @@ comman.name.configure.kotlin=Configure Kotlin
|
||||
command.name.configure.0=Configure {0}
|
||||
notification.title.script.configuration.has.been.changed=Script configurations has been changed.
|
||||
notification.text.script.configuration.has.been.changed=Gradle Project needs to be imported to load changes.
|
||||
script.configurations.will.be.available.after.import=Gradle Kotlin DSL script configuration is missing. Import project to get script code insight.
|
||||
script.configurations.will.be.available.after.load.changes=Gradle Kotlin DSL script configuration is missing. Load Script Configurations to get script code insight.
|
||||
action.label.import.project=Import Project
|
||||
action.label.enable.auto.import=Enable Auto-Import
|
||||
action.text.load.script.configurations=Load Script Configurations
|
||||
action.description.load.script.configurations=Gradle Kotlin DSL script configuration has been changed. Load changes to get script code insight without loading the external Gradle project.
|
||||
action.description.load.script.configurations=Gradle Kotlin DSL script configuration has been changed. Load changes to get script code insight without loading the external Gradle project.
|
||||
|
||||
@@ -31,6 +31,9 @@ fun runPartialGradleImport(project: Project) {
|
||||
}
|
||||
}
|
||||
|
||||
fun getMissingConfigurationNotificationText() = KotlinIdeaGradleBundle.message("script.configurations.will.be.available.after.import")
|
||||
fun getMissingConfigurationActionText() = KotlinIdeaGradleBundle.message("action.label.import.project")
|
||||
|
||||
private const val kotlinDslNotificationGroupId = "Gradle Kotlin DSL Scripts"
|
||||
private var Project.notificationPanel: ScriptConfigurationChangedNotification?
|
||||
by UserDataProperty<Project, ScriptConfigurationChangedNotification>(Key.create("load.script.configuration.panel"))
|
||||
|
||||
+3
@@ -42,6 +42,9 @@ fun runPartialGradleImport(project: Project) {
|
||||
}
|
||||
}
|
||||
|
||||
fun getMissingConfigurationNotificationText() = KotlinIdeaGradleBundle.message("script.configurations.will.be.available.after.load.changes")
|
||||
fun getMissingConfigurationActionText() = KotlinIdeaGradleBundle.message("action.text.load.script.configurations")
|
||||
|
||||
private var Project.shouldShowLoadConfiguraionsAction: Boolean?
|
||||
by UserDataProperty<Project, Boolean>(Key.create("load.script.configuration.action"))
|
||||
|
||||
|
||||
+3
@@ -87,6 +87,9 @@ class GradleScriptingSupport(
|
||||
override fun hasCachedConfiguration(file: KtFile): Boolean =
|
||||
configuration.scriptModel(file.originalFile.virtualFile) != null
|
||||
|
||||
// TODO: can be true during import
|
||||
override fun isConfigurationLoadingInProgress(file: KtFile): Boolean = false
|
||||
|
||||
override fun getOrLoadConfiguration(virtualFile: VirtualFile, preloadedKtFile: KtFile?): ScriptCompilationConfigurationWrapper? {
|
||||
return classpathRoots.getScriptConfiguration(virtualFile)
|
||||
}
|
||||
|
||||
+25
-14
@@ -23,22 +23,33 @@ class GradleScriptOutOfSourceNotificationProvider(private val project: Project)
|
||||
if (!isGradleKotlinScript(file)) return null
|
||||
if (file.fileType != KotlinFileType.INSTANCE) return null
|
||||
|
||||
if (isInAffectedGradleProjectFiles(project, file.path)) return null
|
||||
|
||||
return EditorNotificationPanel().apply {
|
||||
text(KotlinIdeaGradleBundle.message("text.the.associated.gradle.project.isn.t.imported"))
|
||||
val loadScriptConfigurationText = KotlinIdeaGradleBundle.message("action.label.text.load.script.configuration")
|
||||
createActionLabel(loadScriptConfigurationText) {
|
||||
ScriptConfigurationManager.getInstance(project).forceReloadConfiguration(file, loaderForOutOfProjectScripts)
|
||||
if (!isInAffectedGradleProjectFiles(project, file.path)) {
|
||||
return EditorNotificationPanel().apply {
|
||||
text(KotlinIdeaGradleBundle.message("text.the.associated.gradle.project.isn.t.imported"))
|
||||
val loadScriptConfigurationText = KotlinIdeaGradleBundle.message("action.label.text.load.script.configuration")
|
||||
createActionLabel(loadScriptConfigurationText) {
|
||||
ScriptConfigurationManager.getInstance(project).forceReloadConfiguration(file, loaderForOutOfProjectScripts)
|
||||
}
|
||||
val link = createActionLabel("") {}
|
||||
link.setIcon(AllIcons.General.ContextHelp)
|
||||
link.setUseIconAsLink(true)
|
||||
link.toolTipText = KotlinIdeaGradleBundle.message(
|
||||
"tool.tip.text.the.external.gradle.project.needs.to.be.imported.to.get.this.script.analyzed",
|
||||
loadScriptConfigurationText
|
||||
)
|
||||
}
|
||||
val link = createActionLabel("") {}
|
||||
link.setIcon(AllIcons.General.ContextHelp)
|
||||
link.setUseIconAsLink(true)
|
||||
link.toolTipText = KotlinIdeaGradleBundle.message(
|
||||
"tool.tip.text.the.external.gradle.project.needs.to.be.imported.to.get.this.script.analyzed",
|
||||
loadScriptConfigurationText
|
||||
)
|
||||
}
|
||||
|
||||
if (GradleScriptingSupportProvider.getInstance(project).shouldShowNotificationToRunGradleImport(file)) {
|
||||
return EditorNotificationPanel().apply {
|
||||
text(getMissingConfigurationNotificationText())
|
||||
createActionLabel(getMissingConfigurationActionText()) {
|
||||
runPartialGradleImport(project)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
private val loaderForOutOfProjectScripts by lazy {
|
||||
|
||||
+11
@@ -146,6 +146,7 @@ class GradleScriptingSupportProvider(val project: Project) : ScriptingSupport.Pr
|
||||
}
|
||||
|
||||
override fun hasCachedConfiguration(file: KtFile): Boolean = false
|
||||
override fun isConfigurationLoadingInProgress(file: KtFile): Boolean = false
|
||||
|
||||
override fun getOrLoadConfiguration(
|
||||
virtualFile: VirtualFile,
|
||||
@@ -166,6 +167,16 @@ class GradleScriptingSupportProvider(val project: Project) : ScriptingSupport.Pr
|
||||
override fun recreateRootsCache(): ScriptClassRootsCache = ScriptClassRootsCache.empty(project)
|
||||
}
|
||||
|
||||
fun shouldShowNotificationToRunGradleImport(file: VirtualFile): Boolean {
|
||||
if (isGradleKotlinScript(file)) {
|
||||
findRoot(file)?.let { return false }
|
||||
|
||||
val externalProjectSettings = findExternalProjectSettings(file) ?: return false
|
||||
return kotlinDslScriptsModelImportSupported(getGradleVersion(project, externalProjectSettings))
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getInstance(project: Project): GradleScriptingSupportProvider =
|
||||
EPN.getPoint(project).extensionList.firstIsInstance()
|
||||
|
||||
Reference in New Issue
Block a user