Skip to content

Commit 1754403

Browse files
darthorimarintellij-monorepo-bot
authored andcommitted
[lsp] refactoring, move tcpClient/tcpConnection near tcpServer so the similar code is closer
LSP-166 GitOrigin-RevId: 10692c5c5e651c9ce4a8d5cadca3af1e5c228606
1 parent 61759e8 commit 1754403

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

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

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ private fun run(runConfig: KotlinLspServerRunConfig) {
8181

8282
is KotlinLspServerMode.Socket -> {
8383
logSystemInfo()
84-
tcpConnection(mode) { input, output ->
84+
tcpConnection(
85+
clientMode = mode is KotlinLspServerMode.Socket.Client,
86+
port = mode.port,
87+
) { input, output ->
8588
handleRequests(input, output, config, mode)
8689
}
8790
}
@@ -181,29 +184,3 @@ private fun preloadKotlinStdlibWhenRunningFromSources() {
181184
KotlinArtifacts.kotlinStdlib
182185
}
183186
}
184-
185-
private suspend fun tcpConnection(mode: KotlinLspServerMode.Socket, body: suspend CoroutineScope.(InputStream, OutputStream) -> Unit) {
186-
when (mode) {
187-
is KotlinLspServerMode.Socket.Client -> {
188-
tcpClient(mode.port, body)
189-
}
190-
191-
is KotlinLspServerMode.Socket.Server -> {
192-
tcpServer(mode.port, body)
193-
}
194-
}
195-
}
196-
197-
/**
198-
* VSC opens a **server** socket for LSP to connect to it.
199-
*/
200-
private suspend fun tcpClient(port: Int, body: suspend CoroutineScope.(InputStream, OutputStream) -> Unit) {
201-
val socket = runInterruptible(Dispatchers.IO) {
202-
Socket("localhost", port)
203-
}
204-
socket.use {
205-
coroutineScope {
206-
body(socket.getInputStream(), socket.getOutputStream())
207-
}
208-
}
209-
}

0 commit comments

Comments
 (0)