Fix imported script functionality in JSR-223/REPL:
- setup compilation properly to take imported scripts into account - add compiled imported scripts into generated results = calculate ScriptLightVirtualFile path as relative - simplifies imported scripts location
This commit is contained in:
+2
-2
@@ -30,7 +30,6 @@ import kotlin.script.experimental.dependencies.ScriptDependencies
|
||||
import kotlin.script.experimental.host.*
|
||||
import kotlin.script.experimental.jvm.*
|
||||
import kotlin.script.experimental.jvm.compat.mapToDiagnostics
|
||||
import kotlin.script.experimental.jvm.impl.refineWith
|
||||
import kotlin.script.experimental.jvm.impl.toClassPathOrEmpty
|
||||
import kotlin.script.experimental.jvm.impl.toDependencies
|
||||
|
||||
@@ -97,7 +96,8 @@ class ScriptLightVirtualFile(name: String, private val _path: String?, text: Str
|
||||
charset = CharsetToolkit.UTF8_CHARSET
|
||||
}
|
||||
|
||||
override fun getPath(): String = _path ?: super.getPath()
|
||||
override fun getPath(): String = _path ?: if (parent != null) parent.path + "/" + name else name
|
||||
|
||||
override fun getCanonicalPath(): String? = path
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -140,7 +140,7 @@ class KJvmReplCompilerImpl(val hostConfiguration: ScriptingHostConfiguration) :
|
||||
KotlinCodegenFacade.generatePackage(
|
||||
generationState,
|
||||
snippetKtFile.script!!.containingKtFile.packageFqName,
|
||||
setOf(snippetKtFile.script!!.containingKtFile),
|
||||
sourceFiles,
|
||||
CompilationErrorHandler.THROW_EXCEPTION
|
||||
)
|
||||
|
||||
|
||||
+3
-1
@@ -103,7 +103,9 @@ class ReplCodeAnalyzer(environment: KotlinCoreEnvironment) {
|
||||
}
|
||||
|
||||
private fun doAnalyze(linePsi: KtFile, importedScripts: List<KtFile>, codeLine: ReplCodeLine): ReplLineAnalysisResult {
|
||||
scriptDeclarationFactory.setDelegateFactory(FileBasedDeclarationProviderFactory(resolveSession.storageManager, listOf(linePsi)))
|
||||
scriptDeclarationFactory.setDelegateFactory(
|
||||
FileBasedDeclarationProviderFactory(resolveSession.storageManager, listOf(linePsi) + importedScripts)
|
||||
)
|
||||
replState.submitLine(linePsi, codeLine)
|
||||
|
||||
val context = topDownAnalyzer.analyzeDeclarations(topDownAnalysisContext.topDownAnalysisMode, listOf(linePsi) + importedScripts)
|
||||
|
||||
Reference in New Issue
Block a user