@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.CliBindingTrace
16
16
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
17
17
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
18
18
import org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM
19
+ import org.jetbrains.kotlin.cli.jvm.config.addJavaSourceRoots
19
20
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
20
21
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
21
22
import org.jetbrains.kotlin.config.CommonConfigurationKeys
@@ -86,6 +87,7 @@ private val GRADLE_DSL_DEPENDENCY_PATTERN = Regex("^gradle-(?:kotlin-dsl|core).*
86
87
* files and expressions.
87
88
*/
88
89
private class CompilationEnvironment (
90
+ workspaceRoots : Set <Path >,
89
91
classPath : Set <Path >
90
92
) : Closeable {
91
93
private val disposable = Disposer .newDisposable()
@@ -112,6 +114,7 @@ private class CompilationEnvironment(
112
114
put(CommonConfigurationKeys .LANGUAGE_VERSION_SETTINGS , languageVersionSettings)
113
115
put(CLIConfigurationKeys .MESSAGE_COLLECTOR_KEY , LoggingMessageCollector )
114
116
add(ComponentRegistrar .PLUGIN_COMPONENT_REGISTRARS , ScriptingCompilerConfigurationComponentRegistrar ())
117
+ addJavaSourceRoots(workspaceRoots.map { it.toFile() })
115
118
addJvmClasspathRoots(classPath.map { it.toFile() })
116
119
117
120
// Setup script templates (e.g. used by Gradle's Kotlin DSL)
@@ -160,6 +163,8 @@ private class CompilationEnvironment(
160
163
configFiles = EnvironmentConfigFiles .JVM_CONFIG_FILES
161
164
)
162
165
166
+ // TODO: Use environment.addKotlinSourceRoots(workspaceRoots) and update those instead of using a custom SourcePath/SourceFile mechanism
167
+
163
168
val project = environment.project
164
169
if (project is MockProject ) {
165
170
project.registerService(NullableNotNullManager ::class .java, KotlinNullableNotNullManager (project))
@@ -219,12 +224,12 @@ enum class CompilationKind {
219
224
* Incrementally compiles files and expressions.
220
225
* The basic strategy for compiling one file at-a-time is outlined in OneFilePerformance.
221
226
*/
222
- class Compiler (classPath : Set <Path >, buildScriptClassPath : Set <Path > = emptySet()) : Closeable {
227
+ class Compiler (workspaceRoots : Set < Path >, classPath : Set <Path >, buildScriptClassPath : Set <Path > = emptySet()) : Closeable {
223
228
private var closed = false
224
229
private val localFileSystem: VirtualFileSystem
225
230
226
- private val defaultCompileEnvironment = CompilationEnvironment (classPath)
227
- private val buildScriptCompileEnvironment = buildScriptClassPath.takeIf { it.isNotEmpty() }?.let (:: CompilationEnvironment )
231
+ private val defaultCompileEnvironment = CompilationEnvironment (workspaceRoots, classPath)
232
+ private val buildScriptCompileEnvironment = buildScriptClassPath.takeIf { it.isNotEmpty() }?.let { CompilationEnvironment (workspaceRoots, it) }
228
233
private val compileLock = ReentrantLock () // TODO: Lock at file-level
229
234
230
235
companion object {
0 commit comments