@@ -11,6 +11,8 @@ import org.javacs.kt.externalsources.JarClassContentProvider
11
11
import org.javacs.kt.util.AsyncExecutor
12
12
import org.javacs.kt.util.TemporaryDirectory
13
13
import org.javacs.kt.util.parseURI
14
+ import org.javacs.kt.progress.Progress
15
+ import org.javacs.kt.progress.LanguageClientProgress
14
16
import java.net.URI
15
17
import java.io.Closeable
16
18
import java.nio.file.Paths
@@ -31,12 +33,16 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
31
33
private val protocolExtensions = KotlinProtocolExtensionService (uriContentProvider)
32
34
33
35
private lateinit var client: LanguageClient
36
+ private lateinit var progressFactory: Progress .Factory
37
+
34
38
private val async = AsyncExecutor ()
35
39
36
40
override fun connect (client : LanguageClient ) {
37
41
this .client = client
38
42
connectLoggingBackend()
39
43
44
+ progressFactory = LanguageClientProgress .Factory (client)
45
+
40
46
workspaces.connect(client)
41
47
textDocuments.connect(client)
42
48
@@ -73,43 +79,21 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
73
79
config.completion.snippets.enabled = clientCapabilities?.textDocument?.completion?.completionItem?.snippetSupport ? : false
74
80
75
81
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) }
87
83
88
84
folders.forEachIndexed { i, folder ->
89
85
LOG .info(" Adding workspace folder {}" , folder.name)
90
86
val progressPrefix = " [${i + 1 } /${folders.size} ] ${folder.name} "
91
87
val progressPercent = (100 * i) / folders.size
92
88
93
- reportProgress(WorkDoneProgressReport ().apply {
94
- message = " $progressPrefix : Updating source path"
95
- percentage = progressPercent
96
- })
97
-
89
+ progress?.update(" $progressPrefix : Updating source path" , progressPercent)
98
90
val root = Paths .get(parseURI(folder.uri))
99
91
sourceFiles.addWorkspaceRoot(root)
100
92
101
- reportProgress(WorkDoneProgressReport ().apply {
102
- message = " $progressPrefix : Updating class path"
103
- percentage = progressPercent
104
- })
105
-
93
+ progress?.update(" $progressPrefix : Updating class path" , progressPercent)
106
94
val refreshed = classPath.addWorkspaceRoot(root)
107
95
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)
113
97
sourcePath.refresh()
114
98
}
115
99
}
0 commit comments