Skip to content

Commit 5a38c51

Browse files
committed
Use a request instead of a notification
1 parent d5d7ab3 commit 5a38c51

File tree

6 files changed

+16
-38
lines changed

6 files changed

+16
-38
lines changed

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

Lines changed: 0 additions & 14 deletions
This file was deleted.

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ import org.javacs.kt.util.parseURI
1515
import org.javacs.kt.progress.Progress
1616
import org.javacs.kt.progress.LanguageClientProgress
1717
import org.javacs.kt.semantictokens.semanticTokensLegend
18-
import java.net.URI
1918
import java.io.Closeable
2019
import java.nio.file.Paths
2120
import java.util.concurrent.CompletableFuture
2221
import java.util.concurrent.CompletableFuture.completedFuture
2322

24-
class KotlinLanguageServer : LanguageServer, Closeable {
23+
class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
2524
val config = Configuration()
2625
val classPath = CompilerClassPath(config.compiler)
2726

@@ -32,9 +31,9 @@ class KotlinLanguageServer : LanguageServer, Closeable {
3231

3332
private val textDocuments = KotlinTextDocumentService(sourceFiles, sourcePath, config, tempDirectory, uriContentProvider)
3433
private val workspaces = KotlinWorkspaceService(sourceFiles, sourcePath, classPath, textDocuments, config)
35-
private val protocolExtensions = KotlinProtocolExtensionService(uriContentProvider)
34+
private val protocolExtensions = KotlinProtocolExtensionService(uriContentProvider, classPath)
3635

37-
private lateinit var client: KotlinLanguageClient
36+
private lateinit var client: LanguageClient
3837

3938
private val async = AsyncExecutor()
4039
private var progressFactory: Progress.Factory = Progress.Factory.None
@@ -51,7 +50,7 @@ class KotlinLanguageServer : LanguageServer, Closeable {
5150
LOG.info("Kotlin Language Server: Version ${VERSION ?: "?"}")
5251
}
5352

54-
fun connect(client: KotlinLanguageClient) {
53+
override fun connect(client: LanguageClient) {
5554
this.client = client
5655
connectLoggingBackend()
5756

@@ -132,14 +131,6 @@ class KotlinLanguageServer : LanguageServer, Closeable {
132131
InitializeResult(serverCapabilities, serverInfo)
133132
}
134133

135-
override fun initialized(params: InitializedParams?) {
136-
try {
137-
client.buildOutputLocationSet(classPath.outputDirectory.absolutePath)
138-
} catch (ex: UnsupportedOperationException) {
139-
LOG.info("Client does not support notification kotlin/buildOutputLocationSet")
140-
}
141-
}
142-
143134
private fun connectLoggingBackend() {
144135
val backend: (LogMessage) -> Unit = {
145136
client.logMessage(MessageParams().apply {
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package org.javacs.kt
22

33
import org.eclipse.lsp4j.*
4-
import org.javacs.kt.externalsources.JarClassContentProvider
5-
import org.javacs.kt.externalsources.toKlsURI
64
import org.javacs.kt.util.AsyncExecutor
7-
import org.javacs.kt.util.noResult
85
import org.javacs.kt.util.parseURI
9-
import java.net.URI
10-
import java.net.URISyntaxException
116
import java.util.concurrent.CompletableFuture
127

138
class KotlinProtocolExtensionService(
14-
private val uriContentProvider: URIContentProvider
9+
private val uriContentProvider: URIContentProvider,
10+
private val cp: CompilerClassPath
1511
) : KotlinProtocolExtensions {
1612
private val async = AsyncExecutor()
1713

1814
override fun jarClassContents(textDocument: TextDocumentIdentifier): CompletableFuture<String?> = async.compute {
1915
uriContentProvider.contentOf(parseURI(textDocument.uri))
2016
}
17+
18+
override fun getBuildOutputLocation(): CompletableFuture<String?> = async.compute {
19+
cp.outputDirectory.absolutePath
20+
}
2121
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ import java.util.concurrent.CompletableFuture
99
interface KotlinProtocolExtensions {
1010
@JsonRequest
1111
fun jarClassContents(textDocument: TextDocumentIdentifier): CompletableFuture<String?>
12+
13+
@JsonRequest
14+
fun getBuildOutputLocation(): CompletableFuture<String?>
1215
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import com.beust.jcommander.JCommander
44
import com.beust.jcommander.Parameter
55
import java.util.concurrent.Executors
66
import org.eclipse.lsp4j.launch.LSPLauncher
7-
import org.eclipse.lsp4j.ConfigurationParams
8-
import org.eclipse.lsp4j.ConfigurationItem
9-
import org.eclipse.lsp4j.jsonrpc.Launcher
107
import org.javacs.kt.util.ExitingInputStream
118
import org.javacs.kt.util.tcpStartServer
129
import org.javacs.kt.util.tcpConnectToClient
@@ -44,7 +41,7 @@ fun main(argv: Array<String>) {
4441

4542
val server = KotlinLanguageServer()
4643
val threads = Executors.newSingleThreadExecutor { Thread(it, "client") }
47-
val launcher = Launcher.createLauncher(server, KotlinLanguageClient::class.java, ExitingInputStream(inStream), outStream, threads) { it }
44+
val launcher = LSPLauncher.createServerLauncher(server, ExitingInputStream(inStream), outStream, threads) { it }
4845

4946
server.connect(launcher.remoteProxy)
5047
launcher.startListening()

server/src/test/kotlin/org/javacs/kt/LanguageServerTestFixture.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package org.javacs.kt
22

33
import org.eclipse.lsp4j.*
4+
import org.eclipse.lsp4j.services.LanguageClient
45
import org.junit.Before
56
import org.junit.After
67
import java.nio.file.Path
78
import java.nio.file.Paths
89
import java.util.concurrent.CompletableFuture
910

10-
abstract class LanguageServerTestFixture(relativeWorkspaceRoot: String) : KotlinLanguageClient {
11+
abstract class LanguageServerTestFixture(relativeWorkspaceRoot: String) : LanguageClient {
1112
val workspaceRoot = absoluteWorkspaceRoot(relativeWorkspaceRoot)
1213
val languageServer = createLanguageServer()
1314
val diagnostics = mutableListOf<Diagnostic>()

0 commit comments

Comments
 (0)