22package com.jetbrains.ls.kotlinLsp
33
44import com.intellij.openapi.application.PathManager
5+ import com.intellij.openapi.diagnostic.fileLogger
56import com.jetbrains.ls.api.core.LSServer
67import com.jetbrains.ls.api.core.LSServerContext
78import com.jetbrains.ls.api.features.LSConfiguration
@@ -27,7 +28,9 @@ import org.jetbrains.kotlin.idea.base.plugin.artifacts.KotlinArtifacts
2728import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayoutMode
2829import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayoutModeProvider
2930import org.jetbrains.kotlin.idea.compiler.configuration.isRunningFromSources
31+ import java.nio.file.Path
3032import kotlin.io.path.absolutePathString
33+ import kotlin.io.path.createDirectories
3134import kotlin.io.path.createTempDirectory
3235import kotlin.system.exitProcess
3336
@@ -45,10 +48,13 @@ fun main(args: Array<String>) {
4548 }
4649}
4750
51+ // use after `initKotlinLspLogger` call
52+ private val LOG by lazy { fileLogger() }
53+
4854private fun run (runConfig : KotlinLspServerRunConfig ) {
4955 val mode = runConfig.mode
5056 initKotlinLspLogger(writeToStdOut = mode != KotlinLspServerMode .Stdio )
51- initIdeaPaths()
57+ initIdeaPaths(runConfig.systemPath )
5258 setLspKotlinPluginModeIfRunningFromProductionLsp()
5359 val config = createConfiguration()
5460
@@ -112,17 +118,21 @@ private suspend fun handleRequests(connection: LspConnection, runConfig: KotlinL
112118 }
113119}
114120
115- private fun initIdeaPaths () {
121+ private fun initIdeaPaths (systemPath : Path ? ) {
116122 val fromSources = getIJPathIfRunningFromSources()
117123 if (fromSources != null ) {
118124 System .setProperty(" idea.home.path" , fromSources)
119125 System .setProperty(" idea.config.path" , " $fromSources /config/idea" )
120126 System .setProperty(" idea.system.path" , " $fromSources /system/idea" )
121127 }
122128 else {
123- val tmp = createTempDirectory(" idea-home" ).absolutePathString()
124- System .setProperty(" idea.home.path" , tmp)
129+ val path = systemPath?.createDirectories() ? : createTempDirectory(" idea-system" )
130+ System .setProperty(" idea.home.path" , " $path " )
131+ System .setProperty(" idea.config.path" , " $path /config" )
132+ System .setProperty(" idea.system.path" , " $path /system" )
125133 }
134+ LOG .info(" idea.config.path=${System .getProperty(" idea.config.path" )} " )
135+ LOG .info(" idea.system.path=${System .getProperty(" idea.system.path" )} " )
126136}
127137
128138private fun setLspKotlinPluginModeIfRunningFromProductionLsp () {
0 commit comments