Minor: introduce helper method to check registry option
This commit is contained in:
+2
-6
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.idea.scripting.gradle
|
|||||||
|
|
||||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.util.registry.Registry
|
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -20,11 +19,8 @@ import org.jetbrains.kotlin.psi.KtFile
|
|||||||
import org.jetbrains.kotlin.scripting.definitions.ScriptDefinition
|
import org.jetbrains.kotlin.scripting.definitions.ScriptDefinition
|
||||||
|
|
||||||
class GradleScriptConfigurationLoader(project: Project) : DefaultScriptConfigurationLoader(project) {
|
class GradleScriptConfigurationLoader(project: Project) : DefaultScriptConfigurationLoader(project) {
|
||||||
private val useProjectImport: Boolean
|
|
||||||
get() = Registry.`is`("kotlin.gradle.scripts.useIdeaProjectImport", false)
|
|
||||||
|
|
||||||
override fun shouldRunInBackground(scriptDefinition: ScriptDefinition): Boolean {
|
override fun shouldRunInBackground(scriptDefinition: ScriptDefinition): Boolean {
|
||||||
return if (useProjectImport) false else super.shouldRunInBackground(scriptDefinition)
|
return if (useScriptConfigurationFromImportOnly()) false else super.shouldRunInBackground(scriptDefinition)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadDependencies(
|
override fun loadDependencies(
|
||||||
@@ -35,7 +31,7 @@ class GradleScriptConfigurationLoader(project: Project) : DefaultScriptConfigura
|
|||||||
): Boolean {
|
): Boolean {
|
||||||
if (!isGradleKotlinScript(ktFile.originalFile.virtualFile)) return false
|
if (!isGradleKotlinScript(ktFile.originalFile.virtualFile)) return false
|
||||||
|
|
||||||
if (useProjectImport) {
|
if (useScriptConfigurationFromImportOnly()) {
|
||||||
// do nothing, project import notification will be already showed
|
// do nothing, project import notification will be already showed
|
||||||
// and configuration for gradle build scripts will be saved at the end of import
|
// and configuration for gradle build scripts will be saved at the end of import
|
||||||
// todo: use default configuration loader for out-of-project scripts?
|
// todo: use default configuration loader for out-of-project scripts?
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.idea.scripting.gradle
|
package org.jetbrains.kotlin.idea.scripting.gradle
|
||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.util.registry.Registry
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiManager
|
import com.intellij.psi.PsiManager
|
||||||
@@ -64,3 +65,7 @@ const val minimal_gradle_version_supported = "6.0"
|
|||||||
fun kotlinDslScriptsModelImportSupported(currentGradleVersion: String): Boolean {
|
fun kotlinDslScriptsModelImportSupported(currentGradleVersion: String): Boolean {
|
||||||
return GradleVersion.version(currentGradleVersion) >= GradleVersion.version(minimal_gradle_version_supported)
|
return GradleVersion.version(currentGradleVersion) >= GradleVersion.version(minimal_gradle_version_supported)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun useScriptConfigurationFromImportOnly(): Boolean {
|
||||||
|
return Registry.`is`("kotlin.gradle.scripts.useIdeaProjectImport", false)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user