Ask to update runtime library when increasing language version for module
This commit is contained in:
@@ -25,7 +25,6 @@ import com.intellij.openapi.roots.ModuleRootModificationUtil
|
||||
import com.intellij.openapi.roots.ex.ProjectRootManagerEx
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.CoroutineSupport
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
@@ -36,9 +35,6 @@ import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgu
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinWithGradleConfigurator
|
||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet
|
||||
import org.jetbrains.kotlin.idea.facet.getRuntimeLibraryVersion
|
||||
import org.jetbrains.kotlin.idea.util.projectStructure.allModules
|
||||
import org.jetbrains.kotlin.idea.versions.findKotlinRuntimeLibrary
|
||||
import org.jetbrains.kotlin.idea.versions.updateLibraries
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
sealed class ChangeCoroutineSupportFix(
|
||||
@@ -70,17 +66,8 @@ sealed class ChangeCoroutineSupportFix(
|
||||
return
|
||||
}
|
||||
|
||||
if (runtimeUpdateRequired) {
|
||||
val library = findKotlinRuntimeLibrary(module)
|
||||
if (library != null) {
|
||||
val rc = Messages.showOkCancelDialog(project,
|
||||
"Coroutines support requires version 1.1 or later of the Kotlin runtime library. " +
|
||||
"Would you like to update the runtime library in your project?",
|
||||
super.getText(),
|
||||
Messages.getQuestionIcon())
|
||||
if (rc != Messages.OK) return
|
||||
updateLibraries(project, listOf(library))
|
||||
}
|
||||
if (runtimeUpdateRequired && !askUpdateRuntime(module, LanguageFeature.Coroutines.sinceApiVersion)) {
|
||||
return
|
||||
}
|
||||
|
||||
val facetSettings = KotlinFacet.get(module)?.configuration?.settings ?: return
|
||||
@@ -90,6 +77,7 @@ sealed class ChangeCoroutineSupportFix(
|
||||
facetSettings.versionInfo.languageLevel = LanguageVersion.KOTLIN_1_1
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class InProject(element: PsiElement, coroutineSupport: CoroutineSupport) : ChangeCoroutineSupportFix(element, coroutineSupport) {
|
||||
|
||||
@@ -18,11 +18,13 @@ package org.jetbrains.kotlin.idea.quickfix
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.ModuleUtilCore
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.ModuleRootManager
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil
|
||||
import com.intellij.openapi.roots.ex.ProjectRootManagerEx
|
||||
import com.intellij.openapi.roots.libraries.Library
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
@@ -89,6 +91,10 @@ sealed class EnableUnsupportedFeatureFix(
|
||||
return
|
||||
}
|
||||
|
||||
if (runtimeUpdateRequired && !askUpdateRuntime(module, feature.sinceApiVersion)) {
|
||||
return
|
||||
}
|
||||
|
||||
ModuleRootModificationUtil.updateModel(module) {
|
||||
with(facetSettings.versionInfo) {
|
||||
if (!apiVersionOnly) {
|
||||
@@ -155,15 +161,25 @@ fun checkUpdateRuntime(project: Project, requiredVersion: ApiVersion): Boolean {
|
||||
parsedModuleRuntimeVersion != null && parsedModuleRuntimeVersion < requiredVersion
|
||||
}
|
||||
if (modulesWithOutdatedRuntime.isNotEmpty()) {
|
||||
val rc = Messages.showOkCancelDialog(project,
|
||||
"This language feature requires version $requiredVersion or later of the Kotlin runtime library. " +
|
||||
"Would you like to update the runtime library in your project?",
|
||||
"Update runtime library",
|
||||
Messages.getQuestionIcon())
|
||||
if (rc != Messages.OK) return false
|
||||
|
||||
val librariesToUpdate = modulesWithOutdatedRuntime.mapNotNull(::findKotlinRuntimeLibrary)
|
||||
updateLibraries(project, librariesToUpdate)
|
||||
if (askUpdateRuntime(project, requiredVersion,
|
||||
modulesWithOutdatedRuntime.mapNotNull(::findKotlinRuntimeLibrary))) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun askUpdateRuntime(project: Project, requiredVersion: ApiVersion, librariesToUpdate: List<Library>): Boolean {
|
||||
val rc = Messages.showOkCancelDialog(project,
|
||||
"This language feature requires version $requiredVersion or later of the Kotlin runtime library. " +
|
||||
"Would you like to update the runtime library in your project?",
|
||||
"Update Runtime Library",
|
||||
Messages.getQuestionIcon())
|
||||
if (rc != Messages.OK) return false
|
||||
|
||||
updateLibraries(project, librariesToUpdate)
|
||||
return true
|
||||
}
|
||||
|
||||
fun askUpdateRuntime(module: Module, requiredVersion: ApiVersion): Boolean {
|
||||
val library = findKotlinRuntimeLibrary(module) ?: return true
|
||||
return askUpdateRuntime(module.project, requiredVersion, listOf(library))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user