Skip to content

Commit 275115f

Browse files
committed
Implement LanguageClientProgress
1 parent 03a1a93 commit 275115f

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,37 @@
11
package org.javacs.kt.progress
22

3+
import org.eclipse.lsp4j.services.LanguageClient
4+
import org.eclipse.lsp4j.jsonrpc.messages.Either
5+
import org.eclipse.lsp4j.ProgressParams
6+
import org.eclipse.lsp4j.WorkDoneProgressNotification
7+
import org.eclipse.lsp4j.WorkDoneProgressBegin
8+
import org.eclipse.lsp4j.WorkDoneProgressReport
9+
import org.eclipse.lsp4j.WorkDoneProgressEnd
10+
11+
class LanguageClientProgress(
12+
private val label: String,
13+
private val token: Either<String, Number>,
14+
private val client: LanguageClient
15+
) : Progress {
16+
init {
17+
reportProgress(WorkDoneProgressBegin().also {
18+
it.title = "Kotlin: $label"
19+
it.percentage = 0
20+
})
21+
}
22+
23+
override fun update(message: String?, percent: Int?) {
24+
reportProgress(WorkDoneProgressReport().also {
25+
it.message = message
26+
it.percentage = percent
27+
})
28+
}
29+
30+
override fun close() {
31+
reportProgress(WorkDoneProgressEnd())
32+
}
33+
34+
private fun reportProgress(notification: WorkDoneProgressNotification) {
35+
client.notifyProgress(ProgressParams(token, notification))
36+
}
37+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
package org.javacs.kt.progress
22

33
import java.io.Closeable
4+
import java.util.concurrent.CompletableFuture
45

56
/** A facility for emitting progress notifications. */
67
interface Progress : Closeable {
78
/**
89
* Updates the progress percentage. The
910
* value should be in the range [0, 100].
1011
*/
11-
fun update(percent: Int): Unit
12+
fun update(message: String? = null, percent: Int? = null)
1213

1314
interface Factory {
1415
/**
1516
* Creates a new progress listener with
1617
* the given label. The label is intended
1718
* to be human-readable.
1819
*/
19-
fun create(label: String): Progress
20+
fun create(label: String): CompletableFuture<Progress>
2021
}
2122
}

0 commit comments

Comments
 (0)