Skip to content

Commit 2db6693

Browse files
committed
Merge branch 'tcp'
2 parents 18fd7d3 + 0b0d429 commit 2db6693

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

EDITORS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ Add the following to your coc-settings.json file:
4242
Note that you may need to substitute `kotlin-language-server` with `kotlin-language-server.bat` on Windows.
4343

4444
## Other Editors
45-
Install a [Language Server Protocol client](https://microsoft.github.io/language-server-protocol/implementors/tools/) for your tool. Then invoke the language server executable in a client-specific way. The server uses `stdio` to send and receive `JSON-RPC` messages.
45+
Install a [Language Server Protocol client](https://microsoft.github.io/language-server-protocol/implementors/tools/) for your tool. Then invoke the language server executable in a client-specific way.
46+
47+
The server uses `stdio` by default to send and receive `JSON-RPC` messages, but can be launched with the argument `--tcpPort=port` for TCP support.

server/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ dependencies {
5252
implementation 'org.jetbrains:fernflower:1.0'
5353
implementation 'com.pinterest.ktlint:ktlint-core:0.34.2'
5454
implementation 'com.pinterest.ktlint:ktlint-ruleset-standard:0.34.2'
55+
implementation 'com.beust:jcommander:1.78'
5556

5657
// Re-add to depend on Kotlin plugin classes directly. Note that
5758
// this plugin uses the normal imports (com.intellij.*)

server/src/main/kotlin/org/javacs/kt/Main.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
package org.javacs.kt
22

3+
import com.beust.jcommander.JCommander
4+
import com.beust.jcommander.Parameter
35
import java.util.concurrent.Executors
46
import org.eclipse.lsp4j.launch.LSPLauncher
57
import org.eclipse.lsp4j.ConfigurationParams
68
import org.eclipse.lsp4j.ConfigurationItem
79
import org.javacs.kt.util.ExitingInputStream
810

9-
fun main(args: Array<String>) {
11+
class Args {
12+
@Parameter(names = ["--tcpPort", "-p"])
13+
var tcpPort: Int? = null
14+
}
15+
16+
fun main(argv: Array<String>) {
1017
// Redirect java.util.logging calls (e.g. from LSP4J)
1118
LOG.connectJULFrontend()
1219

20+
val args = Args().also { JCommander.newBuilder().addObject(it).build().parse(*argv) }
21+
val (inStream, outStream) = args.tcpPort?.let { tcpConnectToClient(it) } ?: Pair(System.`in`, System.out)
22+
1323
val server = KotlinLanguageServer()
14-
val input = ExitingInputStream(System.`in`)
1524
val threads = Executors.newSingleThreadExecutor { Thread(it, "client") }
16-
val launcher = LSPLauncher.createServerLauncher(server, input, System.out, threads, { it })
25+
val launcher = LSPLauncher.createServerLauncher(server, ExitingInputStream(inStream), outStream, threads, { it })
1726

1827
server.connect(launcher.remoteProxy)
1928
launcher.startListening()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.javacs.kt
2+
3+
import java.io.InputStream
4+
import java.io.OutputStream
5+
import java.net.ServerSocket
6+
7+
/**
8+
* Starts a TCP server socket. Blocks until the first
9+
* client has connected, then returns a pair of IO streams.
10+
*/
11+
fun tcpConnectToClient(port: Int): Pair<InputStream, OutputStream> =
12+
ServerSocket(port).accept().let { Pair(it.inputStream, it.outputStream) }

0 commit comments

Comments
 (0)