Fix "Multiple Script Definitions" notification for settings.gradle.kts
^KT-29832 Fixed
This commit is contained in:
+10
-2
@@ -29,8 +29,7 @@ import org.jetbrains.kotlin.scripting.compiler.plugin.KotlinScriptDefinitionAdap
|
|||||||
|
|
||||||
class MultipleScriptDefinitionsChecker(private val project: Project) : EditorNotifications.Provider<EditorNotificationPanel>() {
|
class MultipleScriptDefinitionsChecker(private val project: Project) : EditorNotifications.Provider<EditorNotificationPanel>() {
|
||||||
|
|
||||||
override fun getKey(): Key<EditorNotificationPanel> =
|
override fun getKey(): Key<EditorNotificationPanel> = KEY
|
||||||
KEY
|
|
||||||
|
|
||||||
override fun createNotificationPanel(file: VirtualFile, fileEditor: FileEditor): EditorNotificationPanel? {
|
override fun createNotificationPanel(file: VirtualFile, fileEditor: FileEditor): EditorNotificationPanel? {
|
||||||
if (file.fileType != KotlinFileType.INSTANCE) return null
|
if (file.fileType != KotlinFileType.INSTANCE) return null
|
||||||
@@ -49,6 +48,7 @@ class MultipleScriptDefinitionsChecker(private val project: Project) : EditorNot
|
|||||||
}
|
}
|
||||||
.toList()
|
.toList()
|
||||||
if (allApplicableDefinitions.size < 2) return null
|
if (allApplicableDefinitions.size < 2) return null
|
||||||
|
if (areDefinitionsForGradleKts(allApplicableDefinitions)) return null
|
||||||
|
|
||||||
return createNotification(
|
return createNotification(
|
||||||
ktFile,
|
ktFile,
|
||||||
@@ -56,6 +56,14 @@ class MultipleScriptDefinitionsChecker(private val project: Project) : EditorNot
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun areDefinitionsForGradleKts(allApplicableDefinitions: List<KotlinScriptDefinition>): Boolean {
|
||||||
|
if (allApplicableDefinitions.size == 2) {
|
||||||
|
return (allApplicableDefinitions[0] as? KotlinScriptDefinitionFromAnnotatedTemplate)?.scriptFilePattern?.pattern == "^(settings|.+\\.settings)\\.gradle\\.kts\$"
|
||||||
|
&& (allApplicableDefinitions[1] as? KotlinScriptDefinitionFromAnnotatedTemplate)?.scriptFilePattern?.pattern == ".*\\.gradle\\.kts"
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val KEY = Key.create<EditorNotificationPanel>("MultipleScriptDefinitionsChecker")
|
private val KEY = Key.create<EditorNotificationPanel>("MultipleScriptDefinitionsChecker")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user