1
1
use std:: time:: Duration ;
2
+ use tokio:: time:: Instant ;
2
3
3
4
use helix_core:: diagnostic:: DiagnosticProvider ;
4
5
use helix_core:: syntax:: LanguageServerFeature ;
@@ -13,7 +14,6 @@ use helix_view::handlers::diagnostics::DiagnosticEvent;
13
14
use helix_view:: handlers:: lsp:: PullDiagnosticsEvent ;
14
15
use helix_view:: handlers:: Handlers ;
15
16
use helix_view:: { DocumentId , Editor } ;
16
- use tokio:: time:: Instant ;
17
17
18
18
use crate :: events:: OnModeSwitch ;
19
19
use crate :: job;
@@ -74,87 +74,30 @@ pub(super) fn register_hooks(handlers: &Handlers) {
74
74
}
75
75
76
76
#[ derive( Debug ) ]
77
- pub ( super ) struct PullDiagnosticsHandler {
78
- no_inter_file_dependency_timeout : Option < tokio:: time:: Instant > ,
79
- }
77
+ pub ( super ) struct PullDiagnosticsHandler { }
80
78
81
79
impl PullDiagnosticsHandler {
82
- pub fn new ( ) -> PullDiagnosticsHandler {
83
- PullDiagnosticsHandler {
84
- no_inter_file_dependency_timeout : None ,
85
- }
80
+ pub fn new ( ) -> Self {
81
+ PullDiagnosticsHandler { }
86
82
}
87
83
}
88
84
89
- const TIMEOUT : Duration = Duration :: from_millis ( 500 ) ;
90
- const TIMEOUT_NO_INTER_FILE_DEPENDENCY : Duration = Duration :: from_millis ( 125 ) ;
91
-
92
85
impl helix_event:: AsyncHook for PullDiagnosticsHandler {
93
86
type Event = PullDiagnosticsEvent ;
94
87
95
88
fn handle_event (
96
89
& mut self ,
97
- event : Self :: Event ,
98
- timeout : Option < tokio:: time:: Instant > ,
90
+ _event : Self :: Event ,
91
+ _timeout : Option < tokio:: time:: Instant > ,
99
92
) -> Option < tokio:: time:: Instant > {
100
- if timeout. is_none ( ) {
101
- dispatch_pull_diagnostic_for_document ( event. document_id , false ) ;
102
- self . no_inter_file_dependency_timeout = Some ( Instant :: now ( ) ) ;
103
- }
104
-
105
- if self
106
- . no_inter_file_dependency_timeout
107
- . is_some_and ( |nifd_timeout| {
108
- nifd_timeout. duration_since ( Instant :: now ( ) ) > TIMEOUT_NO_INTER_FILE_DEPENDENCY
109
- } )
110
- {
111
- dispatch_pull_diagnostic_for_document ( event. document_id , true ) ;
112
- self . no_inter_file_dependency_timeout = Some ( Instant :: now ( ) ) ;
113
- } ;
114
-
115
- Some ( Instant :: now ( ) + TIMEOUT )
93
+ Some ( Instant :: now ( ) + Duration :: from_millis ( 150 ) )
116
94
}
117
95
118
96
fn finish_debounce ( & mut self ) {
119
97
dispatch_pull_diagnostic_for_open_documents ( ) ;
120
98
}
121
99
}
122
100
123
- fn dispatch_pull_diagnostic_for_document (
124
- document_id : DocumentId ,
125
- exclude_language_servers_without_inter_file_dependency : bool ,
126
- ) {
127
- job:: dispatch_blocking ( move |editor, _| {
128
- let Some ( doc) = editor. document ( document_id) else {
129
- return ;
130
- } ;
131
-
132
- let language_servers = doc
133
- . language_servers_with_feature ( LanguageServerFeature :: PullDiagnostics )
134
- . filter ( |ls| ls. is_initialized ( ) )
135
- . filter ( |ls| {
136
- if !exclude_language_servers_without_inter_file_dependency {
137
- return true ;
138
- } ;
139
- ls. capabilities ( )
140
- . diagnostic_provider
141
- . as_ref ( )
142
- . is_some_and ( |dp| match dp {
143
- lsp:: DiagnosticServerCapabilities :: Options ( options) => {
144
- options. inter_file_dependencies
145
- }
146
- lsp:: DiagnosticServerCapabilities :: RegistrationOptions ( options) => {
147
- options. diagnostic_options . inter_file_dependencies
148
- }
149
- } )
150
- } ) ;
151
-
152
- for language_server in language_servers {
153
- pull_diagnostics_for_document ( doc, language_server) ;
154
- }
155
- } )
156
- }
157
-
158
101
fn dispatch_pull_diagnostic_for_open_documents ( ) {
159
102
job:: dispatch_blocking ( move |editor, _| {
160
103
let documents = editor. documents . values ( ) ;
@@ -204,9 +147,14 @@ pub fn pull_diagnostics_for_document(
204
147
let document_id = doc. id ( ) ;
205
148
206
149
tokio:: spawn ( async move {
207
- match future. await {
150
+ match future. 0 . await {
208
151
Ok ( result) => {
209
152
job:: dispatch ( move |editor, _| {
153
+ if let Some ( language_server) = editor. language_server_by_id ( language_server_id)
154
+ {
155
+ language_server. mark_work_as_done ( future. 1 ) ;
156
+ } ;
157
+
210
158
handle_pull_diagnostics_response ( editor, result, provider, uri, document_id)
211
159
} )
212
160
. await
@@ -230,6 +178,7 @@ pub fn pull_diagnostics_for_document(
230
178
editor. document ( document_id) ,
231
179
editor. language_server_by_id ( language_server_id) ,
232
180
) {
181
+ language_server. mark_work_as_done ( future. 1 ) ;
233
182
pull_diagnostics_for_document ( doc, language_server) ;
234
183
}
235
184
} )
0 commit comments