@@ -15,11 +15,8 @@ private val logger = logger<TextDocumentServiceQueue>()
15
15
16
16
class TextDocumentServiceQueue (private val textDocumentService : () -> TextDocumentService ? ) {
17
17
18
- private val service: TextDocumentService ?
19
- get() = textDocumentService()
20
-
21
18
private val mutex = Mutex ()
22
- private suspend fun <T > executeTask (id : String , logDescription : Any? = null, task : suspend () -> T ): T {
19
+ private suspend fun <T > executeTask (id : String , logDescription : Any? = null, task : suspend (TextDocumentService ) -> T ): T ? {
23
20
logger.trace {
24
21
val summary = " $id : operation queued."
25
22
val description = logDescription?.toString()
@@ -32,7 +29,10 @@ class TextDocumentServiceQueue(private val textDocumentService: () -> TextDocume
32
29
withContext(Dispatchers .IO ) {
33
30
logger.trace { " $id : executing on the IO context." }
34
31
try {
35
- task()
32
+ textDocumentService()?.let { task(it) } ? : run {
33
+ logger.error(" Cannot get the service to perform task $id ." )
34
+ null
35
+ }
36
36
} finally {
37
37
logger.trace { " $id : finished." }
38
38
}
@@ -41,31 +41,31 @@ class TextDocumentServiceQueue(private val textDocumentService: () -> TextDocume
41
41
}
42
42
43
43
suspend fun didOpen (params : DidOpenTextDocumentParams ) {
44
- executeTask(" didOpen notification" , params) {
45
- service? .didOpen(params)
44
+ executeTask(" didOpen notification" , params) { service ->
45
+ service.didOpen(params)
46
46
}
47
47
}
48
48
49
49
suspend fun didClose (params : DidCloseTextDocumentParams ) {
50
- executeTask(" didClose notification" , params) {
51
- service? .didClose(params)
50
+ executeTask(" didClose notification" , params) { service ->
51
+ service.didClose(params)
52
52
}
53
53
}
54
54
55
55
suspend fun didSave (params : DidSaveTextDocumentParams ) {
56
- executeTask(" didSave notification" , params) {
57
- service? .didSave(params)
56
+ executeTask(" didSave notification" , params) { service ->
57
+ service.didSave(params)
58
58
}
59
59
}
60
60
61
61
suspend fun didChange (params : DidChangeTextDocumentParams ) {
62
- executeTask(" didChange notification" , params) {
63
- service? .didChange(params)
62
+ executeTask(" didChange notification" , params) { service ->
63
+ service.didChange(params)
64
64
}
65
65
}
66
66
67
67
suspend fun completion (params : CompletionParams ): Either <List <CompletionItem >, CompletionList>? =
68
- executeTask(" completion request" , params) {
69
- service? .completion(params)?.await()
68
+ executeTask(" completion request" , params) { service ->
69
+ service.completion(params)?.await()
70
70
}
71
71
}
0 commit comments