Skip to content

Commit 8679452

Browse files
gregshintellij-monorepo-bot
authored andcommitted
[analyzer] init config/system paths in bundle mode
GitOrigin-RevId: 5cd7ad3a6f3bbf5e66b9624cc34810598604fc69
1 parent 7c3a2d7 commit 8679452

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

kotlin-lsp/src/com/jetbrains/ls/kotlinLsp/KotlinLspServer.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package com.jetbrains.ls.kotlinLsp
33

44
import com.intellij.openapi.application.PathManager
5+
import com.intellij.openapi.diagnostic.fileLogger
56
import com.jetbrains.ls.api.core.LSServer
67
import com.jetbrains.ls.api.core.LSServerContext
78
import com.jetbrains.ls.api.features.LSConfiguration
@@ -27,7 +28,9 @@ import org.jetbrains.kotlin.idea.base.plugin.artifacts.KotlinArtifacts
2728
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayoutMode
2829
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayoutModeProvider
2930
import org.jetbrains.kotlin.idea.compiler.configuration.isRunningFromSources
31+
import java.nio.file.Path
3032
import kotlin.io.path.absolutePathString
33+
import kotlin.io.path.createDirectories
3134
import kotlin.io.path.createTempDirectory
3235
import 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+
4854
private 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

128138
private fun setLspKotlinPluginModeIfRunningFromProductionLsp() {

kotlin-lsp/src/com/jetbrains/ls/kotlinLsp/KotlinLspServerRunConfig.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ package com.jetbrains.ls.kotlinLsp
22

33
import com.github.ajalt.clikt.core.CliktCommand
44
import com.github.ajalt.clikt.core.PrintHelpMessage
5-
import com.github.ajalt.clikt.parameters.options.default
6-
import com.github.ajalt.clikt.parameters.options.flag
7-
import com.github.ajalt.clikt.parameters.options.help
8-
import com.github.ajalt.clikt.parameters.options.option
9-
import com.github.ajalt.clikt.parameters.options.validate
5+
import com.github.ajalt.clikt.parameters.options.*
106
import com.github.ajalt.clikt.parameters.types.int
7+
import com.github.ajalt.clikt.parameters.types.path
118
import com.jetbrains.lsp.implementation.TcpConnectionConfig
9+
import java.nio.file.Path
1210

1311
data class KotlinLspServerRunConfig(
14-
val mode: KotlinLspServerMode
12+
val mode: KotlinLspServerMode,
13+
val systemPath: Path? = null,
1514
)
1615

1716
sealed interface KotlinLspServerMode {
@@ -37,12 +36,15 @@ sealed class KotlinLspCommand {
3736
}
3837

3938
private class Parser : CliktCommand(name = "kotlin-lsp") {
40-
val socket: Int by option().int().default(9999).help("A port which will be used for a Kotlin LSP connection. Default is 9999")
39+
val socket: Int by option().int().default(9999)
40+
.help("A port which will be used for a Kotlin LSP connection. Default is 9999")
4141
val stdio: Boolean by option().flag()
4242
.help("Whether the Kotlin LSP server is used in stdio mode. If not set, server mode will be used with a port specified by `${::socket.name}`")
4343
val client: Boolean by option().flag()
4444
.help("Whether the Kotlin LSP server is used in client mode. If not set, server mode will be used with a port specified by `${::socket.name}`")
4545
.validate { if (it && stdio) fail("Can't use stdio mode with client mode") }
46+
val systemPath: Path? by option().path()
47+
.help("Path for Kotlin LSP caches and indexes")
4648

4749
val multiclient: Boolean by option().flag()
4850
.help("Whether the Kotlin LSP server is used in multiclient mode. If not set, server will be shut down after the first client disconnects.`")
@@ -58,7 +60,7 @@ private class Parser : CliktCommand(name = "kotlin-lsp") {
5860
client -> KotlinLspServerMode.Socket(TcpConnectionConfig.Client(port = socket))
5961
else -> KotlinLspServerMode.Socket(TcpConnectionConfig.Server(port = socket, isMulticlient = multiclient))
6062
}
61-
return KotlinLspServerRunConfig(mode)
63+
return KotlinLspServerRunConfig(mode, systemPath)
6264
}
6365

6466
override fun run() {}

kotlin-vscode/client/src/lspClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ async function getRunningJavaServerLspOptions(): Promise<ServerOptions | null> {
183183
args.push(
184184
'-classpath', extractPath + path.sep + '*',
185185
'com.jetbrains.ls.kotlinLsp.KotlinLspServerKt', '--client',
186+
'--system-path', getContext().globalStorageUri.fsPath,
186187
);
187188
if (runWithJavaSupport()) {
188189
args.push('--with-java')

0 commit comments

Comments
 (0)