Skip to content

Commit 55fa0aa

Browse files
committed
Report progress for workspace folders
1 parent 42d5562 commit 55fa0aa

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
3030
private val workspaces = KotlinWorkspaceService(sourceFiles, sourcePath, classPath, textDocuments, config)
3131
private val protocolExtensions = KotlinProtocolExtensionService(uriContentProvider)
3232

33+
private lateinit var client: LanguageClient
3334
private val async = AsyncExecutor()
3435

3536
override fun connect(client: LanguageClient) {
36-
connectLoggingBackend(client)
37+
this.client = client
38+
connectLoggingBackend()
3739

3840
workspaces.connect(client)
3941
textDocuments.connect(client)
@@ -70,12 +72,22 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
7072
val clientCapabilities = params.capabilities
7173
config.completion.snippets.enabled = clientCapabilities?.textDocument?.completion?.completionItem?.snippetSupport ?: false
7274

73-
if (params.rootUri != null) {
74-
LOG.info("Adding workspace {} to source path", params.rootUri)
75+
val folders = params.workspaceFolders
76+
client.notifyProgress(ProgressParams(params.workDoneToken, WorkDoneProgressBegin().apply {
77+
title = "Adding workspace folders"
78+
percentage = 0
79+
}))
7580

76-
val root = Paths.get(parseURI(params.rootUri))
81+
folders.forEachIndexed { i, folder ->
82+
LOG.info("Adding workspace {} to source path", params.rootUri)
83+
client.notifyProgress(ProgressParams(params.workDoneToken, WorkDoneProgressReport().apply {
84+
message = "[${i + 1}/${folders.size}] ${folder.name}"
85+
percentage = (100 * i) / folders.size
86+
}))
7787

88+
val root = Paths.get(parseURI(folder.uri))
7889
sourceFiles.addWorkspaceRoot(root)
90+
7991
val refreshed = classPath.addWorkspaceRoot(root)
8092
if (refreshed) {
8193
sourcePath.refresh()
@@ -85,7 +97,7 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
8597
InitializeResult(serverCapabilities)
8698
}
8799

88-
private fun connectLoggingBackend(client: LanguageClient) {
100+
private fun connectLoggingBackend() {
89101
val backend: (LogMessage) -> Unit = {
90102
client.logMessage(MessageParams().apply {
91103
type = it.level.toLSPMessageType()

0 commit comments

Comments
 (0)