@@ -128,7 +128,7 @@ def __init__(self, session_view: SessionViewProtocol, buffer_id: int, uri: Docum
128
128
self ._pending_changes : PendingChanges | None = None
129
129
self .diagnostics : list [tuple [Diagnostic , sublime .Region ]] = []
130
130
self .diagnostics_data_per_severity : dict [tuple [int , bool ], DiagnosticSeverityData ] = {}
131
- self .diagnostics_version = - 1
131
+ self ._diagnostics_version = - 1
132
132
self .diagnostics_flags = 0
133
133
self ._diagnostics_are_visible = False
134
134
self .document_diagnostic_needs_refresh = False
@@ -496,8 +496,13 @@ def do_document_diagnostic_async(
496
496
return
497
497
if mgr .should_ignore_diagnostics (self ._last_known_uri , self .session .config ):
498
498
return
499
+ change_count = view .change_count ()
499
500
if version is None :
500
- version = view .change_count ()
501
+ version = change_count
502
+ elif version < change_count :
503
+ return
504
+ if version == self ._diagnostics_version :
505
+ return
501
506
if self ._document_diagnostic_pending_request :
502
507
if self ._document_diagnostic_pending_request .version == version and not forced_update :
503
508
return
@@ -520,18 +525,17 @@ def _on_document_diagnostic_async(self, version: int, response: DocumentDiagnost
520
525
self ._document_diagnostic_pending_request = None
521
526
self ._if_view_unchanged (self ._apply_document_diagnostic_async , version )(response )
522
527
523
- def _apply_document_diagnostic_async (
524
- self , view : sublime .View | None , response : DocumentDiagnosticReport
525
- ) -> None :
528
+ def _apply_document_diagnostic_async (self , view : sublime .View | None , response : DocumentDiagnosticReport ) -> None :
526
529
self .session .diagnostics_result_ids [self ._last_known_uri ] = response .get ('resultId' )
527
530
if is_full_document_diagnostic_report (response ):
528
531
self .session .m_textDocument_publishDiagnostics (
529
532
{'uri' : self ._last_known_uri , 'diagnostics' : response ['items' ]})
530
- for uri , diagnostic_report in response .get ('relatedDocuments' , {}):
531
- sb = self .session .get_session_buffer_for_uri_async (uri )
532
- if sb :
533
- cast (SessionBuffer , sb )._apply_document_diagnostic_async (
534
- None , cast (DocumentDiagnosticReport , diagnostic_report ))
533
+ if 'relatedDocuments' in response :
534
+ for uri , diagnostic_report in response ['relatedDocuments' ].items ():
535
+ sb = self .session .get_session_buffer_for_uri_async (uri )
536
+ if sb :
537
+ cast (SessionBuffer , sb )._apply_document_diagnostic_async (
538
+ None , cast (DocumentDiagnosticReport , diagnostic_report ))
535
539
536
540
def _on_document_diagnostic_error_async (self , version : int , error : ResponseError ) -> None :
537
541
self ._document_diagnostic_pending_request = None
@@ -580,7 +584,7 @@ def on_diagnostics_async(
580
584
self .diagnostics_data_per_severity = data_per_severity
581
585
582
586
def present () -> None :
583
- self .diagnostics_version = diagnostics_version
587
+ self ._diagnostics_version = diagnostics_version
584
588
self .diagnostics = diagnostics
585
589
self ._diagnostics_are_visible = bool (diagnostics )
586
590
for sv in self .session_views :
@@ -604,6 +608,12 @@ def present() -> None:
604
608
condition = lambda : bool (view and view .is_valid () and view .change_count () == diagnostics_version ),
605
609
)
606
610
611
+ def has_latest_diagnostics (self ) -> bool :
612
+ view = self .some_view ()
613
+ if view is None :
614
+ return False
615
+ return self ._diagnostics_version == view .change_count ()
616
+
607
617
# --- textDocument/semanticTokens ----------------------------------------------------------------------------------
608
618
609
619
def do_semantic_tokens_async (self , view : sublime .View , only_viewport : bool = False ) -> None :
0 commit comments