Skip to content

Commit 56012fd

Browse files
darthorimarintellij-monorepo-bot
authored andcommitted
[lsp] log arguments with which the lsp was started to a user
GitOrigin-RevId: 2291a9b5a1be64aedfbff8698beb5e25fd2e3cc1
1 parent 538bb12 commit 56012fd

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private fun run(runConfig: KotlinLspServerRunConfig) {
6262
val stdout = System.out
6363
System.setOut(System.err)
6464
stdioConnection(System.`in`, stdout) { connection ->
65-
handleRequests(connection, config, mode)
65+
handleRequests(connection, runConfig, config, mode)
6666
}
6767
}
6868

@@ -71,7 +71,7 @@ private fun run(runConfig: KotlinLspServerRunConfig) {
7171
tcpConnection(
7272
mode.config,
7373
) { connection ->
74-
handleRequests(connection, config, mode)
74+
handleRequests(connection, runConfig, config, mode)
7575
}
7676
}
7777
}
@@ -80,7 +80,7 @@ private fun run(runConfig: KotlinLspServerRunConfig) {
8080
}
8181

8282
context(LSServerContext)
83-
private suspend fun handleRequests(connection: LspConnection, config: LSConfiguration, mode: KotlinLspServerMode) {
83+
private suspend fun handleRequests(connection: LspConnection, runConfig: KotlinLspServerRunConfig, config: LSConfiguration, mode: KotlinLspServerMode) {
8484
val shutdownOnExitSignal = when (mode) {
8585
is KotlinLspServerMode.Socket -> when (val tcpConfig = mode.config) {
8686
is TcpConnectionConfig.Client -> true
@@ -99,7 +99,7 @@ private suspend fun handleRequests(connection: LspConnection, config: LSConfigur
9999
outgoing,
100100
handler,
101101
createCoroutineContext = { lspClient ->
102-
Client.contextElement(lspClient)
102+
Client.contextElement(lspClient, runConfig)
103103
},
104104
) { lsp ->
105105
if (exitSignal != null) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ data class KotlinLspServerRunConfig(
1515
)
1616

1717
sealed interface KotlinLspServerMode {
18-
object Stdio : KotlinLspServerMode
18+
data object Stdio : KotlinLspServerMode
1919

2020
data class Socket(val config: TcpConnectionConfig) : KotlinLspServerMode
2121
}

kotlin-lsp/src/com/jetbrains/ls/kotlinLsp/connection/Client.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
22
package com.jetbrains.ls.kotlinLsp.connection
33

4+
import com.jetbrains.ls.kotlinLsp.KotlinLspServerRunConfig
45
import com.jetbrains.lsp.implementation.LspClient
56
import com.jetbrains.lsp.protocol.TraceValue
67
import kotlinx.coroutines.ThreadContextElement
78
import kotlinx.coroutines.asContextElement
89

910
data class Client(
1011
val lspClient: LspClient,
11-
val trace: TraceValue? = null,
12+
val runConfig: KotlinLspServerRunConfig?,
13+
val trace: TraceValue?,
1214
) {
1315
companion object {
1416
val current: Client?
1517
get() = ClientConnectionHolder.ThreadBound.get()?.connection
1618

17-
fun contextElement(lspClient: LspClient): ThreadContextElement<*> {
19+
fun contextElement(lspClient: LspClient, runConfig: KotlinLspServerRunConfig?): ThreadContextElement<*> {
1820
return ClientConnectionHolder.ThreadBound.asContextElement(
19-
ClientConnectionHolder(Client(lspClient))
21+
ClientConnectionHolder(Client(lspClient, runConfig, trace = null))
2022
)
2123
}
2224

kotlin-lsp/src/com/jetbrains/ls/kotlinLsp/requests/core/initialize.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ import com.jetbrains.ls.imports.gradle.GradleWorkspaceImporter
1414
import com.jetbrains.ls.imports.jps.JpsWorkspaceImporter
1515
import com.jetbrains.ls.imports.json.JsonWorkspaceImporter
1616
import com.jetbrains.ls.kotlinLsp.connection.Client
17+
import com.jetbrains.ls.kotlinLsp.util.getSystemInfo
1718
import com.jetbrains.ls.kotlinLsp.util.importProject
1819
import com.jetbrains.ls.kotlinLsp.util.registerStdlibAndJdk
1920
import com.jetbrains.ls.kotlinLsp.util.sendSystemInfoToClient
21+
import com.jetbrains.lsp.implementation.LspClient
2022
import com.jetbrains.lsp.implementation.LspHandlerContext
2123
import com.jetbrains.lsp.implementation.LspHandlersBuilder
2224
import com.jetbrains.lsp.implementation.reportProgress
@@ -31,6 +33,8 @@ context(LSServer, LSConfiguration)
3133
internal fun LspHandlersBuilder.initializeRequest() {
3234
request(Initialize) { initParams ->
3335
Client.update { it.copy(trace = initParams.trace) }
36+
37+
lspClient.sendRunConfigurationInfoToClient()
3438
lspClient.sendSystemInfoToClient()
3539

3640
LOG.info("Got `initialize` request from ${initParams.clientInfo ?: "unknown"}\nparams:\n${LSP.json.encodeToString(InitializeParams.serializer(), initParams)}")
@@ -109,6 +113,15 @@ internal fun LspHandlersBuilder.initializeRequest() {
109113
}
110114
}
111115

116+
private fun LspClient.sendRunConfigurationInfoToClient() {
117+
val client = Client.current ?: return
118+
val runConfig = client.runConfig
119+
notify(
120+
LogMessageNotification,
121+
LogMessageParams(MessageType.Info, "Process stared with\n${runConfig}"),
122+
)
123+
}
124+
112125
context(LSServer, LSConfiguration, LspHandlerContext)
113126
private suspend fun indexFolders(
114127
folders: List<WorkspaceFolder>,

0 commit comments

Comments
 (0)