diff --git a/src/main/kotlin/texlab/WorkspaceAction.kt b/src/main/kotlin/texlab/WorkspaceAction.kt deleted file mode 100644 index 2e2aacae6..000000000 --- a/src/main/kotlin/texlab/WorkspaceAction.kt +++ /dev/null @@ -1,9 +0,0 @@ -package texlab - -import kotlinx.coroutines.CompletableDeferred - -sealed class WorkspaceAction { - class Get(val response: CompletableDeferred) : WorkspaceAction() - - class Put(val updater: (Workspace) -> Document) : WorkspaceAction() -} diff --git a/src/main/kotlin/texlab/WorkspaceActor.kt b/src/main/kotlin/texlab/WorkspaceActor.kt index 7ef607b5e..4963e9c6e 100644 --- a/src/main/kotlin/texlab/WorkspaceActor.kt +++ b/src/main/kotlin/texlab/WorkspaceActor.kt @@ -8,15 +8,15 @@ import kotlin.coroutines.CoroutineContext class WorkspaceActor : CoroutineScope { override val coroutineContext: CoroutineContext = Dispatchers.Default + Job() - private val actor = actor { + private val actor = actor { var documents = listOf() for (message in channel) { val workspace = Workspace(documents) when (message) { - is WorkspaceAction.Get -> { + is Action.Get -> { message.response.complete(workspace) } - is WorkspaceAction.Put -> { + is Action.Put -> { val document = message.updater(workspace) documents = documents.filterNot { it.uri == document.uri } .plus(document) @@ -27,7 +27,7 @@ class WorkspaceActor : CoroutineScope { suspend fun get(): Workspace { val response = CompletableDeferred() - actor.send(WorkspaceAction.Get(response)) + actor.send(Action.Get(response)) return response.await() } @@ -36,6 +36,12 @@ class WorkspaceActor : CoroutineScope { } fun put(updater: (Workspace) -> Document) = runBlocking { - actor.send(WorkspaceAction.Put(updater)) + actor.send(Action.Put(updater)) + } + + private sealed class Action { + class Get(val response: CompletableDeferred) : Action() + + class Put(val updater: (Workspace) -> Document) : Action() } }