1
+ use std:: collections:: HashSet ;
1
2
use std:: time:: Duration ;
2
3
use tokio:: time:: Instant ;
3
4
@@ -11,7 +12,7 @@ use helix_view::events::{
11
12
DiagnosticsDidChange , DocumentDidChange , DocumentDidOpen , LanguageServerInitialized ,
12
13
} ;
13
14
use helix_view:: handlers:: diagnostics:: DiagnosticEvent ;
14
- use helix_view:: handlers:: lsp:: PullDiagnosticsEvent ;
15
+ use helix_view:: handlers:: lsp:: { PullAllDocumentsDiagnosticsEvent , PullDiagnosticsEvent } ;
15
16
use helix_view:: handlers:: Handlers ;
16
17
use helix_view:: { DocumentId , Editor } ;
17
18
@@ -35,13 +36,15 @@ pub(super) fn register_hooks(handlers: &Handlers) {
35
36
} ) ;
36
37
37
38
let tx = handlers. pull_diagnostics . clone ( ) ;
39
+ let tx_all_documents = handlers. pull_all_documents_diagnostics . clone ( ) ;
38
40
register_hook ! ( move |event: & mut DocumentDidChange <' _>| {
39
41
if event
40
42
. doc
41
43
. has_language_server_with_feature( LanguageServerFeature :: PullDiagnostics )
42
44
{
43
45
let document_id = event. doc. id( ) ;
44
46
send_blocking( & tx, PullDiagnosticsEvent { document_id } ) ;
47
+ send_blocking( & tx_all_documents, PullAllDocumentsDiagnosticsEvent { } ) ;
45
48
}
46
49
Ok ( ( ) )
47
50
} ) ;
@@ -74,11 +77,15 @@ pub(super) fn register_hooks(handlers: &Handlers) {
74
77
}
75
78
76
79
#[ derive( Debug ) ]
77
- pub ( super ) struct PullDiagnosticsHandler { }
80
+ pub ( super ) struct PullDiagnosticsHandler {
81
+ document_ids : HashSet < DocumentId > ,
82
+ }
78
83
79
84
impl PullDiagnosticsHandler {
80
85
pub fn new ( ) -> Self {
81
- PullDiagnosticsHandler { }
86
+ PullDiagnosticsHandler {
87
+ document_ids : Default :: default ( ) ,
88
+ }
82
89
}
83
90
}
84
91
@@ -87,31 +94,80 @@ impl helix_event::AsyncHook for PullDiagnosticsHandler {
87
94
88
95
fn handle_event (
89
96
& mut self ,
90
- _event : Self :: Event ,
97
+ event : Self :: Event ,
91
98
_timeout : Option < tokio:: time:: Instant > ,
92
99
) -> Option < tokio:: time:: Instant > {
100
+ self . document_ids . insert ( event. document_id ) ;
93
101
Some ( Instant :: now ( ) + Duration :: from_millis ( 125 ) )
94
102
}
95
103
96
104
fn finish_debounce ( & mut self ) {
97
- dispatch_pull_diagnostic_for_open_documents ( ) ;
105
+ let document_ids = self . document_ids . clone ( ) ;
106
+ job:: dispatch_blocking ( move |editor, _| {
107
+ for document_id in document_ids {
108
+ let document = editor. document ( document_id) ;
109
+
110
+ let Some ( document) = document else {
111
+ return ;
112
+ } ;
113
+
114
+ let language_servers = document
115
+ . language_servers_with_feature ( LanguageServerFeature :: PullDiagnostics )
116
+ . filter ( |ls| ls. is_initialized ( ) ) ;
117
+
118
+ for language_server in language_servers {
119
+ pull_diagnostics_for_document ( document, language_server) ;
120
+ }
121
+ }
122
+ } )
98
123
}
99
124
}
100
125
101
- fn dispatch_pull_diagnostic_for_open_documents ( ) {
102
- job:: dispatch_blocking ( move |editor, _| {
103
- let documents = editor. documents . values ( ) ;
126
+ #[ derive( Debug ) ]
127
+ pub ( super ) struct PullAllDocumentsDiagnosticHandler { }
128
+
129
+ impl PullAllDocumentsDiagnosticHandler {
130
+ pub fn new ( ) -> Self {
131
+ PullAllDocumentsDiagnosticHandler { }
132
+ }
133
+ }
104
134
105
- for document in documents {
106
- let language_servers = document
107
- . language_servers_with_feature ( LanguageServerFeature :: PullDiagnostics )
108
- . filter ( |ls| ls. is_initialized ( ) ) ;
135
+ impl helix_event:: AsyncHook for PullAllDocumentsDiagnosticHandler {
136
+ type Event = PullAllDocumentsDiagnosticsEvent ;
109
137
110
- for language_server in language_servers {
111
- pull_diagnostics_for_document ( document, language_server) ;
138
+ fn handle_event (
139
+ & mut self ,
140
+ _event : Self :: Event ,
141
+ _timeout : Option < tokio:: time:: Instant > ,
142
+ ) -> Option < tokio:: time:: Instant > {
143
+ Some ( Instant :: now ( ) + Duration :: from_millis ( 500 ) )
144
+ }
145
+
146
+ fn finish_debounce ( & mut self ) {
147
+ job:: dispatch_blocking ( move |editor, _| {
148
+ for document in editor. documents . values ( ) {
149
+ let language_servers = document
150
+ . language_servers_with_feature ( LanguageServerFeature :: PullDiagnostics )
151
+ . filter ( |ls| ls. is_initialized ( ) )
152
+ . filter ( |ls| {
153
+ ls. capabilities ( ) . diagnostic_provider . as_ref ( ) . is_some_and (
154
+ |diagnostic_provider| match diagnostic_provider {
155
+ lsp:: DiagnosticServerCapabilities :: Options ( options) => {
156
+ options. inter_file_dependencies
157
+ }
158
+ lsp:: DiagnosticServerCapabilities :: RegistrationOptions ( options) => {
159
+ options. diagnostic_options . inter_file_dependencies
160
+ }
161
+ } ,
162
+ )
163
+ } ) ;
164
+
165
+ for language_server in language_servers {
166
+ pull_diagnostics_for_document ( document, language_server) ;
167
+ }
112
168
}
113
- }
114
- } )
169
+ } )
170
+ }
115
171
}
116
172
117
173
pub fn pull_diagnostics_for_document (
0 commit comments