@@ -11,27 +11,35 @@ import org.javacs.kt.externalsources.JarClassContentProvider
1111import org.javacs.kt.util.AsyncExecutor
1212import org.javacs.kt.util.TemporaryDirectory
1313import org.javacs.kt.util.parseURI
14+ import org.javacs.kt.progress.Progress
15+ import org.javacs.kt.progress.LanguageClientProgress
1416import java.net.URI
1517import java.io.Closeable
1618import java.nio.file.Paths
1719import java.util.concurrent.CompletableFuture
1820import java.util.concurrent.CompletableFuture.completedFuture
1921
2022class KotlinLanguageServer : LanguageServer , LanguageClientAware , Closeable {
21- private val config = Configuration ()
23+ val config = Configuration ()
2224 val classPath = CompilerClassPath (config.compiler)
2325
2426 private val tempDirectory = TemporaryDirectory ()
2527 private val uriContentProvider = URIContentProvider (JarClassContentProvider (config.externalSources, classPath, tempDirectory))
26- val sourcePath = SourcePath (classPath, uriContentProvider)
28+ val sourcePath = SourcePath (classPath, uriContentProvider, config.indexing )
2729 val sourceFiles = SourceFiles (sourcePath, uriContentProvider)
2830
2931 private val textDocuments = KotlinTextDocumentService (sourceFiles, sourcePath, config, tempDirectory, uriContentProvider)
3032 private val workspaces = KotlinWorkspaceService (sourceFiles, sourcePath, classPath, textDocuments, config)
3133 private val protocolExtensions = KotlinProtocolExtensionService (uriContentProvider)
3234
3335 private lateinit var client: LanguageClient
36+
3437 private val async = AsyncExecutor ()
38+ private var progressFactory: Progress .Factory = Progress .Factory .None
39+ set(factory: Progress .Factory ) {
40+ field = factory
41+ sourcePath.progressFactory = factory
42+ }
3543
3644 override fun connect (client : LanguageClient ) {
3745 this .client = client
@@ -72,44 +80,26 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
7280 val clientCapabilities = params.capabilities
7381 config.completion.snippets.enabled = clientCapabilities?.textDocument?.completion?.completionItem?.snippetSupport ? : false
7482
75- val folders = params.workspaceFolders
76-
77- fun reportProgress (notification : WorkDoneProgressNotification ) {
78- params.workDoneToken?.let {
79- client.notifyProgress(ProgressParams (it, notification))
80- }
83+ if (clientCapabilities?.window?.workDoneProgress ? : false ) {
84+ progressFactory = LanguageClientProgress .Factory (client)
8185 }
8286
83- reportProgress(WorkDoneProgressBegin ().apply {
84- title = " Adding Kotlin workspace folders"
85- percentage = 0
86- })
87+ val folders = params.workspaceFolders
88+ val progress = params.workDoneToken?.let { LanguageClientProgress (" Workspace folders" , it, client) }
8789
8890 folders.forEachIndexed { i, folder ->
8991 LOG .info(" Adding workspace folder {}" , folder.name)
9092 val progressPrefix = " [${i + 1 } /${folders.size} ] ${folder.name} "
9193 val progressPercent = (100 * i) / folders.size
9294
93- reportProgress(WorkDoneProgressReport ().apply {
94- message = " $progressPrefix : Updating source path"
95- percentage = progressPercent
96- })
97-
95+ progress?.update(" $progressPrefix : Updating source path" , progressPercent)
9896 val root = Paths .get(parseURI(folder.uri))
9997 sourceFiles.addWorkspaceRoot(root)
10098
101- reportProgress(WorkDoneProgressReport ().apply {
102- message = " $progressPrefix : Updating class path"
103- percentage = progressPercent
104- })
105-
99+ progress?.update(" $progressPrefix : Updating class path" , progressPercent)
106100 val refreshed = classPath.addWorkspaceRoot(root)
107101 if (refreshed) {
108- reportProgress(WorkDoneProgressReport ().apply {
109- message = " $progressPrefix : Refreshing source path"
110- percentage = progressPercent
111- })
112-
102+ progress?.update(" $progressPrefix : Refreshing source path" , progressPercent)
113103 sourcePath.refresh()
114104 }
115105 }
0 commit comments