@@ -8,6 +8,7 @@ import org.eclipse.lsp4j.services.LanguageClientAware
8
8
import org.eclipse.lsp4j.services.LanguageServer
9
9
import org.javacs.kt.commands.ALL_COMMANDS
10
10
import org.javacs.kt.externalsources.JarClassContentProvider
11
+ import org.javacs.kt.util.AsyncExecutor
11
12
import org.javacs.kt.util.TemporaryDirectory
12
13
import org.javacs.kt.util.parseURI
13
14
import java.net.URI
@@ -29,8 +30,12 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
29
30
private val workspaces = KotlinWorkspaceService (sourceFiles, sourcePath, classPath, textDocuments, config)
30
31
private val protocolExtensions = KotlinProtocolExtensionService (uriContentProvider)
31
32
33
+ private lateinit var client: LanguageClient
34
+ private val async = AsyncExecutor ()
35
+
32
36
override fun connect (client : LanguageClient ) {
33
- connectLoggingBackend(client)
37
+ this .client = client
38
+ connectLoggingBackend()
34
39
35
40
workspaces.connect(client)
36
41
textDocuments.connect(client)
@@ -45,7 +50,7 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
45
50
@JsonDelegate
46
51
fun getProtocolExtensionService (): KotlinProtocolExtensions = protocolExtensions
47
52
48
- override fun initialize (params : InitializeParams ): CompletableFuture <InitializeResult > {
53
+ override fun initialize (params : InitializeParams ): CompletableFuture <InitializeResult > = async.compute {
49
54
val serverCapabilities = ServerCapabilities ()
50
55
serverCapabilities.setTextDocumentSync(TextDocumentSyncKind .Incremental )
51
56
serverCapabilities.workspace = WorkspaceServerCapabilities ()
@@ -67,22 +72,52 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
67
72
val clientCapabilities = params.capabilities
68
73
config.completion.snippets.enabled = clientCapabilities?.textDocument?.completion?.completionItem?.snippetSupport ? : false
69
74
70
- if (params.rootUri != null ) {
71
- LOG .info(" Adding workspace {} to source path" , params.rootUri)
75
+ 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
+ })
72
87
73
- val root = Paths .get(parseURI(params.rootUri))
88
+ folders.forEachIndexed { i, folder ->
89
+ LOG .info(" Adding workspace folder {}" , folder.name)
90
+ val progressPrefix = " [${i + 1 } /${folders.size} ] ${folder.name} "
91
+ val progressPercent = (100 * i) / folders.size
74
92
93
+ reportProgress(WorkDoneProgressReport ().apply {
94
+ message = " $progressPrefix : Updating source path"
95
+ percentage = progressPercent
96
+ })
97
+
98
+ val root = Paths .get(parseURI(folder.uri))
75
99
sourceFiles.addWorkspaceRoot(root)
100
+
101
+ reportProgress(WorkDoneProgressReport ().apply {
102
+ message = " $progressPrefix : Updating class path"
103
+ percentage = progressPercent
104
+ })
105
+
76
106
val refreshed = classPath.addWorkspaceRoot(root)
77
107
if (refreshed) {
108
+ reportProgress(WorkDoneProgressReport ().apply {
109
+ message = " $progressPrefix : Refreshing source path"
110
+ percentage = progressPercent
111
+ })
112
+
78
113
sourcePath.refresh()
79
114
}
80
115
}
81
116
82
- return completedFuture( InitializeResult (serverCapabilities) )
117
+ InitializeResult (serverCapabilities)
83
118
}
84
119
85
- private fun connectLoggingBackend (client : LanguageClient ) {
120
+ private fun connectLoggingBackend () {
86
121
val backend: (LogMessage ) -> Unit = {
87
122
client.logMessage(MessageParams ().apply {
88
123
type = it.level.toLSPMessageType()
@@ -104,6 +139,7 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
104
139
textDocumentService.close()
105
140
classPath.close()
106
141
tempDirectory.close()
142
+ async.shutdown(awaitTermination = true )
107
143
}
108
144
109
145
override fun shutdown (): CompletableFuture <Any > {
0 commit comments