mirror of
https://github.com/latex-lsp/texlab.git
synced 2025-12-23 09:19:21 +00:00
Move WorkspaceAction into WorkspaceActor
This commit is contained in:
parent
637b51b9a1
commit
ee1cabbc30
2 changed files with 11 additions and 14 deletions
|
|
@ -1,9 +0,0 @@
|
|||
package texlab
|
||||
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
|
||||
sealed class WorkspaceAction {
|
||||
class Get(val response: CompletableDeferred<Workspace>) : WorkspaceAction()
|
||||
|
||||
class Put(val updater: (Workspace) -> Document) : WorkspaceAction()
|
||||
}
|
||||
|
|
@ -8,15 +8,15 @@ import kotlin.coroutines.CoroutineContext
|
|||
class WorkspaceActor : CoroutineScope {
|
||||
override val coroutineContext: CoroutineContext = Dispatchers.Default + Job()
|
||||
|
||||
private val actor = actor<WorkspaceAction> {
|
||||
private val actor = actor<Action> {
|
||||
var documents = listOf<Document>()
|
||||
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<Workspace>()
|
||||
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<Workspace>) : Action()
|
||||
|
||||
class Put(val updater: (Workspace) -> Document) : Action()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue