From 5dc7067bd24bc8f8036511c7e1126190cd68df73 Mon Sep 17 00:00:00 2001 From: Andrey Zaytsev Date: Wed, 29 Oct 2025 10:08:01 +0100 Subject: [PATCH] [analyzer] refactor: extract progress to a file GitOrigin-RevId: 78d779182d536b6f632ce4763ebff631ee2096d5 --- .../lsp/implementation/LspHandlers.kt | 26 -------------- .../jetbrains/lsp/implementation/progress.kt | 36 +++++++++++++++++++ 2 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 fleet/lsp.protocol/srcCommonMain/com/jetbrains/lsp/implementation/progress.kt diff --git a/fleet/lsp.protocol/srcCommonMain/com/jetbrains/lsp/implementation/LspHandlers.kt b/fleet/lsp.protocol/srcCommonMain/com/jetbrains/lsp/implementation/LspHandlers.kt index 78e3a7573915..25eb8d204da9 100644 --- a/fleet/lsp.protocol/srcCommonMain/com/jetbrains/lsp/implementation/LspHandlers.kt +++ b/fleet/lsp.protocol/srcCommonMain/com/jetbrains/lsp/implementation/LspHandlers.kt @@ -53,33 +53,7 @@ class LspHandlerContext( context(context: LspHandlerContext) val lspClient: LspClient get() = context.lspClient -fun interface ProgressReporter { - companion object { - val NOOP: ProgressReporter = ProgressReporter {} - } - fun report(progress: WorkDoneProgress) -} -suspend fun LspClient.withProgress( - request: WorkDoneProgressParams, - body: suspend CoroutineScope.(ProgressReporter) -> T -): T = - coroutineScope { - when (val token = request.workDoneToken) { - null -> body(ProgressReporter.NOOP) - else -> { - val state = MutableStateFlow(null) - launch { - state.filterNotNull().collect { p -> - notify(ProgressNotificationType, ProgressParams(token, LSP.json.encodeToJsonElement(WorkDoneProgress.serializer(), p))) - delay(100.milliseconds) - } - }.use { - body(ProgressReporter { p -> state.value = p }) - } - } - } - } class LspRequestHandler( val requestType: RequestType, diff --git a/fleet/lsp.protocol/srcCommonMain/com/jetbrains/lsp/implementation/progress.kt b/fleet/lsp.protocol/srcCommonMain/com/jetbrains/lsp/implementation/progress.kt new file mode 100644 index 000000000000..b3690ac20409 --- /dev/null +++ b/fleet/lsp.protocol/srcCommonMain/com/jetbrains/lsp/implementation/progress.kt @@ -0,0 +1,36 @@ +package com.jetbrains.lsp.implementation + +import com.jetbrains.lsp.protocol.* +import com.jetbrains.lsp.implementation.* +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.filterNotNull +import kotlin.time.Duration.Companion.milliseconds + +fun interface ProgressReporter { + companion object { + val NOOP: ProgressReporter = ProgressReporter {} + } + fun report(progress: WorkDoneProgress) +} + +suspend fun LspClient.withProgress( + request: WorkDoneProgressParams, + body: suspend CoroutineScope.(ProgressReporter) -> T +): T = + coroutineScope { + when (val token = request.workDoneToken) { + null -> body(ProgressReporter.NOOP) + else -> { + val state = MutableStateFlow(null) + launch { + state.filterNotNull().collect { p -> + notify(LSP.ProgressNotificationType, ProgressParams(token, LSP.json.encodeToJsonElement(WorkDoneProgress.serializer(), p))) + delay(100.milliseconds) + } + }.use { + body(ProgressReporter { p -> state.value = p }) + } + } + } + } \ No newline at end of file