Skip to content

Commit 2198743

Browse files
committed
Use new Progress abstraction in initialization
1 parent b32f536 commit 2198743

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

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

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import org.javacs.kt.externalsources.JarClassContentProvider
1111
import org.javacs.kt.util.AsyncExecutor
1212
import org.javacs.kt.util.TemporaryDirectory
1313
import org.javacs.kt.util.parseURI
14+
import org.javacs.kt.progress.Progress
15+
import org.javacs.kt.progress.LanguageClientProgress
1416
import java.net.URI
1517
import java.io.Closeable
1618
import java.nio.file.Paths
@@ -31,12 +33,16 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
3133
private val protocolExtensions = KotlinProtocolExtensionService(uriContentProvider)
3234

3335
private lateinit var client: LanguageClient
36+
private lateinit var progressFactory: Progress.Factory
37+
3438
private val async = AsyncExecutor()
3539

3640
override fun connect(client: LanguageClient) {
3741
this.client = client
3842
connectLoggingBackend()
3943

44+
progressFactory = LanguageClientProgress.Factory(client)
45+
4046
workspaces.connect(client)
4147
textDocuments.connect(client)
4248

@@ -73,43 +79,21 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
7379
config.completion.snippets.enabled = clientCapabilities?.textDocument?.completion?.completionItem?.snippetSupport ?: false
7480

7581
val folders = params.workspaceFolders
76-
77-
fun reportProgress(notification: WorkDoneProgressNotification) {
78-
params.workDoneToken?.let {
79-
client.notifyProgress(ProgressParams(it, notification))
80-
}
81-
}
82-
83-
reportProgress(WorkDoneProgressBegin().apply {
84-
title = "Adding Kotlin workspace folders"
85-
percentage = 0
86-
})
82+
val progress = params.workDoneToken?.let { LanguageClientProgress("Workspace folders", it, client) }
8783

8884
folders.forEachIndexed { i, folder ->
8985
LOG.info("Adding workspace folder {}", folder.name)
9086
val progressPrefix = "[${i + 1}/${folders.size}] ${folder.name}"
9187
val progressPercent = (100 * i) / folders.size
9288

93-
reportProgress(WorkDoneProgressReport().apply {
94-
message = "$progressPrefix: Updating source path"
95-
percentage = progressPercent
96-
})
97-
89+
progress?.update("$progressPrefix: Updating source path", progressPercent)
9890
val root = Paths.get(parseURI(folder.uri))
9991
sourceFiles.addWorkspaceRoot(root)
10092

101-
reportProgress(WorkDoneProgressReport().apply {
102-
message = "$progressPrefix: Updating class path"
103-
percentage = progressPercent
104-
})
105-
93+
progress?.update("$progressPrefix: Updating class path", progressPercent)
10694
val refreshed = classPath.addWorkspaceRoot(root)
10795
if (refreshed) {
108-
reportProgress(WorkDoneProgressReport().apply {
109-
message = "$progressPrefix: Refreshing source path"
110-
percentage = progressPercent
111-
})
112-
96+
progress?.update("$progressPrefix: Refreshing source path", progressPercent)
11397
sourcePath.refresh()
11498
}
11599
}

0 commit comments

Comments
 (0)