@@ -146,6 +146,19 @@ async def initialized(self, sender: Any) -> None:
146
146
147
147
self ._workspace_diagnostics_task = create_sub_task (self .run_workspace_diagnostics (), loop = self .diagnostics_loop )
148
148
149
+ def extend_capabilities (self , capabilities : ServerCapabilities ) -> None :
150
+ if (
151
+ self .parent .client_capabilities is not None
152
+ and self .parent .client_capabilities .text_document is not None
153
+ and self .parent .client_capabilities .text_document .diagnostic is not None
154
+ ):
155
+ capabilities .diagnostic_provider = DiagnosticOptions (
156
+ inter_file_dependencies = True ,
157
+ workspace_diagnostics = False ,
158
+ identifier = f"robotcodelsp_{ uuid .uuid4 ()} " ,
159
+ work_done_progress = True ,
160
+ )
161
+
149
162
@property
150
163
def diagnostics_loop (self ) -> asyncio .AbstractEventLoop :
151
164
if self ._diagnostics_loop is None :
@@ -214,19 +227,6 @@ def _ensure_diagnostics_thread_started(self) -> None:
214
227
if not self ._diagnostics_started .wait (10 ) or not self ._single_diagnostics_started .wait (10 ):
215
228
raise RuntimeError ("Can't start diagnostics worker threads." )
216
229
217
- def extend_capabilities (self , capabilities : ServerCapabilities ) -> None :
218
- if (
219
- self .parent .client_capabilities is not None
220
- and self .parent .client_capabilities .text_document is not None
221
- and self .parent .client_capabilities .text_document .diagnostic is not None
222
- ):
223
- capabilities .diagnostic_provider = DiagnosticOptions (
224
- inter_file_dependencies = True ,
225
- workspace_diagnostics = False ,
226
- identifier = f"robotcodelsp_{ uuid .uuid4 ()} " ,
227
- work_done_progress = True ,
228
- )
229
-
230
230
@async_tasking_event_iterator
231
231
async def collect (sender , document : TextDocument ) -> Optional [DiagnosticsResult ]: # NOSONAR
232
232
...
@@ -298,14 +298,7 @@ def done(t: asyncio.Task[Any]) -> None:
298
298
await asyncio .sleep (0.001 )
299
299
300
300
finally :
301
- self .parent .send_notification (
302
- "textDocument/publishDiagnostics" ,
303
- PublishDiagnosticsParams (
304
- uri = document .document_uri ,
305
- version = document ._version ,
306
- diagnostics = [],
307
- ),
308
- )
301
+ self .publish_diagnostics (document , diagnostics = [])
309
302
310
303
async def cancel_workspace_diagnostics_task (self , sender : Any ) -> None :
311
304
if self ._workspace_diagnostics_task is not None :
@@ -472,15 +465,9 @@ async def _get_diagnostics_for_document(
472
465
collected_keys .append (result .key )
473
466
474
467
if data .entries and send_diagnostics :
475
- self .parent .send_notification (
476
- "textDocument/publishDiagnostics" ,
477
- PublishDiagnosticsParams (
478
- uri = document .document_uri ,
479
- version = document ._version ,
480
- diagnostics = [
481
- l for l in itertools .chain (* [i for i in data .entries .values () if i is not None ])
482
- ],
483
- ),
468
+ self .publish_diagnostics (
469
+ document ,
470
+ diagnostics = [l for l in itertools .chain (* [i for i in data .entries .values () if i is not None ])],
484
471
)
485
472
486
473
except asyncio .CancelledError :
@@ -489,6 +476,16 @@ async def _get_diagnostics_for_document(
489
476
for k in set (data .entries .keys ()) - set (collected_keys ):
490
477
data .entries .pop (k )
491
478
479
+ def publish_diagnostics (self , document : TextDocument , diagnostics : List [Diagnostic ]) -> None :
480
+ self .parent .send_notification (
481
+ "textDocument/publishDiagnostics" ,
482
+ PublishDiagnosticsParams (
483
+ uri = document .document_uri ,
484
+ version = document .version ,
485
+ diagnostics = diagnostics ,
486
+ ),
487
+ )
488
+
492
489
@rpc_method (name = "textDocument/diagnostic" , param_type = DocumentDiagnosticParams )
493
490
@threaded ()
494
491
async def _text_document_diagnostic (
0 commit comments