Run script action in IDE should use kotlin compiler from plugin

^KT-22647 Fixed
This commit is contained in:
Natalia Selezneva
2018-02-28 09:05:50 +03:00
parent 2486be0f86
commit 7d76554966
2 changed files with 12 additions and 4 deletions
@@ -201,6 +201,8 @@ private class ScriptCommandLineState(
params.mainClass = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler" params.mainClass = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler"
params.programParametersList.prepend(filePath) params.programParametersList.prepend(filePath)
params.programParametersList.prepend("-script") params.programParametersList.prepend("-script")
params.programParametersList.prepend(PathUtil.kotlinPathsForIdeaPlugin.homePath.path)
params.programParametersList.prepend("-kotlin-home")
return params return params
} }
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.idea.search.allScope
import org.jetbrains.kotlin.idea.stubindex.KotlinScriptFqnIndex import org.jetbrains.kotlin.idea.stubindex.KotlinScriptFqnIndex
import org.jetbrains.kotlin.idea.test.KotlinCodeInsightTestCase import org.jetbrains.kotlin.idea.test.KotlinCodeInsightTestCase
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import org.jetbrains.kotlin.psi.KtScript import org.jetbrains.kotlin.utils.PathUtil
import org.junit.Assert import org.junit.Assert
import kotlin.test.assertNotEquals import kotlin.test.assertNotEquals
@@ -43,9 +43,9 @@ class StandaloneScriptRunConfigurationTest : KotlinCodeInsightTestCase() {
val javaParameters = getJavaRunParameters(runConfiguration) val javaParameters = getJavaRunParameters(runConfiguration)
val programParametersList = javaParameters.programParametersList.list val programParametersList = javaParameters.programParametersList.list
val (first, second) = programParametersList
Assert.assertEquals("Should pass -script to compiler", "-script", first) programParametersList.checkParameter("-script") { it.contains("simpleScript.kts") }
Assert.assertTrue("Should pass script file to compiler", second.contains("simpleScript.kts")) programParametersList.checkParameter("-kotlin-home") { it == PathUtil.kotlinPathsForIdeaPlugin.homePath.path }
} }
fun testOnFileRename() { fun testOnFileRename() {
@@ -122,6 +122,12 @@ class StandaloneScriptRunConfigurationTest : KotlinCodeInsightTestCase() {
assertEquals(originalWorkingDirectory, runConfiguration.workingDirectory) assertEquals(originalWorkingDirectory, runConfiguration.workingDirectory)
} }
private fun List<String>.checkParameter(name: String, condition: (String) -> Boolean) {
val param = find { it == name } ?: throw AssertionError("Should pass $name to compiler")
val paramValue = this[this.indexOf(param) + 1]
Assert.assertTrue("Check for $name parameter fails: actual value = $paramValue", condition(paramValue))
}
fun moveScriptFile(scriptFile: PsiFile) { fun moveScriptFile(scriptFile: PsiFile) {
ActionRunner.runInsideWriteAction { VfsUtil.createDirectoryIfMissing(scriptFile.virtualFile.parent, "dest") } ActionRunner.runInsideWriteAction { VfsUtil.createDirectoryIfMissing(scriptFile.virtualFile.parent, "dest") }