Switch to templates in the separate script runtime

This commit is contained in:
Ilya Chernikov
2016-10-11 10:03:41 +02:00
parent c2b5c11781
commit 846797ff61
36 changed files with 99 additions and 128 deletions
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.idea.core.script.KotlinScriptConfigurationManager
import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromAnnotatedTemplate
import org.jetbrains.kotlin.script.StandardScriptDefinition
import org.jetbrains.kotlin.script.getScriptDefinition
import kotlin.script.StandardScriptTemplate
class KotlinScriptResolveScopeProvider : ResolveScopeProvider() {
override fun getResolveScope(file: VirtualFile, project: Project): GlobalSearchScope? {
@@ -70,7 +70,7 @@ class KotlinConsoleKeeper(val project: Project) {
//paramList.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")
val kotlinPaths = PathUtil.getKotlinPathsForIdeaPlugin()
val replClassPath = listOf(kotlinPaths.compilerPath, kotlinPaths.reflectPath, kotlinPaths.runtimePath)
val replClassPath = listOf(kotlinPaths.compilerPath, kotlinPaths.reflectPath, kotlinPaths.runtimePath, kotlinPaths.scriptRuntimePath)
.map { it.absolutePath }
.joinToString(File.pathSeparator)
@@ -29,13 +29,9 @@ class KotlinJsr223StandardScriptEngineFactory4Idea : KotlinJsr223JvmScriptEngine
KotlinJsr223JvmScriptEngine4Idea(
Disposer.newDisposable(),
this,
listOf(PathUtil.getKotlinPathsForIdeaPlugin().runtimePath),
"kotlin.script.ScriptTemplateWithArgsAndBindings",
{ ctx ->
val bindings = ctx.getBindings(ScriptContext.ENGINE_SCOPE)
arrayOf(
(bindings[ScriptEngine.ARGV] as? Array<*>) ?: emptyArray<String>(),
bindings) },
arrayOf(Array<String>::class.java, Map::class.java)
listOf(PathUtil.getKotlinPathsForIdeaPlugin().runtimePath, PathUtil.getKotlinPathsForIdeaPlugin().scriptRuntimePath),
"kotlin.script.templates.standard.ScriptTemplateWithBindings",
{ ctx -> arrayOf(ctx.getBindings(ScriptContext.ENGINE_SCOPE)) },
arrayOf(Map::class.java)
)
}
@@ -187,7 +187,7 @@ private class ScriptCommandLineState(environment: ExecutionEnvironment, configur
val params = commonParameters()
val kotlinPaths = PathUtil.getKotlinPathsForIdeaPlugin()
listOf(kotlinPaths.compilerPath, kotlinPaths.reflectPath, kotlinPaths.runtimePath)
listOf(kotlinPaths.compilerPath, kotlinPaths.reflectPath, kotlinPaths.runtimePath, kotlinPaths.scriptRuntimePath)
.map { it.absolutePath }
.forEach { dependencyJar -> params.classPath.add(dependencyJar) }
@@ -125,6 +125,7 @@ private fun updateJar(
val jarPath: File = when (libraryJarDescriptor) {
LibraryJarDescriptor.RUNTIME_JAR -> paths.runtimePath
LibraryJarDescriptor.REFLECT_JAR -> paths.reflectPath
LibraryJarDescriptor.SCRIPT_RUNTIME_JAR -> paths.scriptRuntimePath
LibraryJarDescriptor.TEST_JAR -> paths.kotlinTestPath
LibraryJarDescriptor.RUNTIME_SRC_JAR -> paths.runtimeSourcesPath
LibraryJarDescriptor.JS_STDLIB_JAR -> paths.jsStdLibJarPath
@@ -160,6 +161,7 @@ fun findAllUsedLibraries(project: Project): MultiMap<Library, Module> {
private enum class LibraryJarDescriptor private constructor(val jarName: String, val shouldExist: Boolean) {
RUNTIME_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_JAR, true),
REFLECT_JAR(PathUtil.KOTLIN_JAVA_REFLECT_JAR, false),
SCRIPT_RUNTIME_JAR(PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR, true),
TEST_JAR(PathUtil.KOTLIN_TEST_JAR, false),
RUNTIME_SRC_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_SRC_JAR, false),
JS_STDLIB_JAR(PathUtil.JS_LIB_JAR_NAME, true),
@@ -52,6 +52,7 @@ class KotlinUpdatePluginComponent : ApplicationComponent {
// Force refresh jar handlers
requestFullJarUpdate(ideaPluginPaths.runtimePath)
requestFullJarUpdate(ideaPluginPaths.reflectPath)
requestFullJarUpdate(ideaPluginPaths.scriptRuntimePath)
requestFullJarUpdate(ideaPluginPaths.runtimeSourcesPath)
requestFullJarUpdate(ideaPluginPaths.jsStdLibJarPath)
@@ -55,10 +55,7 @@ class IdeaJsr223Test : PlatformTestCase() {
bindings.put(ScriptEngine.ARGV, arrayOf("42"))
bindings.put("abc", 13)
val res1 = engine.eval("2 + args[0].toInt()")
assertEquals(44, res1)
val res2 = engine.eval("2 + (bindings[\"abc\"] as Int)")
assertEquals(15, res2)
val res1 = engine.eval("2 + (bindings[\"abc\"] as Int)")
assertEquals(15, res1)
}
}