-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathMain.kt
More file actions
55 lines (46 loc) · 2.03 KB
/
Copy pathMain.kt
File metadata and controls
55 lines (46 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package org.javacs.kt
import com.beust.jcommander.JCommander
import com.beust.jcommander.Parameter
import java.util.concurrent.Executors
import org.eclipse.lsp4j.launch.LSPLauncher
import org.javacs.kt.util.ExitingInputStream
import org.javacs.kt.util.tcpStartServer
import org.javacs.kt.util.tcpConnectToClient
class Args {
/*
* The language server can currently be launched in three modes:
* - Stdio, in which case no argument should be specified (used by default)
* - TCP Server, in which case the client has to connect to the specified tcpServerPort (used by the Docker image)
* - TCP Client, in which case the server will connect to the specified tcpClientPort/tcpClientHost (optionally used by VSCode)
*/
@Parameter(names = ["--tcpServerPort", "-sp"])
var tcpServerPort: Int? = null
@Parameter(names = ["--tcpClientPort", "-p"])
var tcpClientPort: Int? = null
@Parameter(names = ["--tcpClientHost", "-h"])
var tcpClientHost: String = "localhost"
@Parameter(names = ["--level"])
var logLevel: String = "info"
@Parameter(names = ["--tcpDebug"])
var tcpDebug: Boolean = false
}
fun main(argv: Array<String>) {
// Redirect java.util.logging calls (e.g. from LSP4J)
LOG.connectJULFrontend()
val args = Args().also { JCommander.newBuilder().addObject(it).build().parse(*argv) }
val (inStream, outStream) = args.tcpClientPort?.let {
// Launch as TCP Client
LOG.connectStdioBackend()
tcpConnectToClient(args.tcpClientHost, it)
} ?: args.tcpServerPort?.let {
// Launch as TCP Server
LOG.connectStdioBackend()
tcpStartServer(it)
} ?: Pair(System.`in`, System.out)
LOG.setLogLevel(args.logLevel)
val server = KotlinLanguageServer(tcpDebug = args.tcpDebug)
val threads = Executors.newSingleThreadExecutor { Thread(it, "client") }
val launcher = LSPLauncher.createServerLauncher(server, ExitingInputStream(inStream), outStream, threads) { it }
server.connect(launcher.remoteProxy)
launcher.startListening()
}