@@ -5,7 +5,7 @@ use std::{
5
5
} ;
6
6
7
7
use ide:: Cancelled ;
8
- use lsp_server:: ExtractError ;
8
+ use lsp_server:: { ExtractError , Response , ResponseError } ;
9
9
use serde:: { de:: DeserializeOwned , Serialize } ;
10
10
use stdx:: thread:: ThreadIntent ;
11
11
@@ -117,15 +117,20 @@ impl RequestDispatcher<'_> {
117
117
}
118
118
return self ;
119
119
}
120
- self . on_with_thread_intent :: < true , ALLOW_RETRYING , R > ( ThreadIntent :: Worker , f)
120
+ self . on_with_thread_intent :: < true , ALLOW_RETRYING , R > (
121
+ ThreadIntent :: Worker ,
122
+ f,
123
+ Self :: content_modified_error,
124
+ )
121
125
}
122
126
123
127
/// Dispatches a non-latency-sensitive request onto the thread pool. When the VFS is marked not
124
- /// ready this will return a default constructed [`R::Result`].
125
- pub ( crate ) fn on_or < const ALLOW_RETRYING : bool , R > (
128
+ /// ready this will return a ` default` constructed [`R::Result`].
129
+ pub ( crate ) fn on_with < R > (
126
130
& mut self ,
127
131
f : fn ( GlobalStateSnapshot , R :: Params ) -> anyhow:: Result < R :: Result > ,
128
132
default : impl FnOnce ( ) -> R :: Result ,
133
+ on_cancelled : fn ( ) -> ResponseError ,
129
134
) -> & mut Self
130
135
where
131
136
R : lsp_types:: request:: Request <
@@ -141,7 +146,7 @@ impl RequestDispatcher<'_> {
141
146
}
142
147
return self ;
143
148
}
144
- self . on_with_thread_intent :: < true , ALLOW_RETRYING , R > ( ThreadIntent :: Worker , f)
149
+ self . on_with_thread_intent :: < true , false , R > ( ThreadIntent :: Worker , f, on_cancelled )
145
150
}
146
151
147
152
/// Dispatches a non-latency-sensitive request onto the thread pool. When the VFS is marked not
@@ -160,7 +165,11 @@ impl RequestDispatcher<'_> {
160
165
}
161
166
return self ;
162
167
}
163
- self . on_with_thread_intent :: < true , ALLOW_RETRYING , R > ( ThreadIntent :: Worker , f)
168
+ self . on_with_thread_intent :: < true , ALLOW_RETRYING , R > (
169
+ ThreadIntent :: Worker ,
170
+ f,
171
+ Self :: content_modified_error,
172
+ )
164
173
}
165
174
166
175
/// Dispatches a latency-sensitive request onto the thread pool. When the VFS is marked not
@@ -183,7 +192,11 @@ impl RequestDispatcher<'_> {
183
192
}
184
193
return self ;
185
194
}
186
- self . on_with_thread_intent :: < true , ALLOW_RETRYING , R > ( ThreadIntent :: LatencySensitive , f)
195
+ self . on_with_thread_intent :: < true , ALLOW_RETRYING , R > (
196
+ ThreadIntent :: LatencySensitive ,
197
+ f,
198
+ Self :: content_modified_error,
199
+ )
187
200
}
188
201
189
202
/// Formatting requests should never block on waiting a for task thread to open up, editors will wait
@@ -198,7 +211,11 @@ impl RequestDispatcher<'_> {
198
211
R :: Params : DeserializeOwned + panic:: UnwindSafe + Send + fmt:: Debug ,
199
212
R :: Result : Serialize ,
200
213
{
201
- self . on_with_thread_intent :: < false , false , R > ( ThreadIntent :: LatencySensitive , f)
214
+ self . on_with_thread_intent :: < false , false , R > (
215
+ ThreadIntent :: LatencySensitive ,
216
+ f,
217
+ Self :: content_modified_error,
218
+ )
202
219
}
203
220
204
221
pub ( crate ) fn finish ( & mut self ) {
@@ -217,6 +234,7 @@ impl RequestDispatcher<'_> {
217
234
& mut self ,
218
235
intent : ThreadIntent ,
219
236
f : fn ( GlobalStateSnapshot , R :: Params ) -> anyhow:: Result < R :: Result > ,
237
+ on_cancelled : fn ( ) -> ResponseError ,
220
238
) -> & mut Self
221
239
where
222
240
R : lsp_types:: request:: Request + ' static ,
@@ -245,11 +263,10 @@ impl RequestDispatcher<'_> {
245
263
match thread_result_to_response :: < R > ( req. id . clone ( ) , result) {
246
264
Ok ( response) => Task :: Response ( response) ,
247
265
Err ( _cancelled) if ALLOW_RETRYING => Task :: Retry ( req) ,
248
- Err ( _cancelled) => Task :: Response ( lsp_server:: Response :: new_err (
249
- req. id ,
250
- lsp_server:: ErrorCode :: ContentModified as i32 ,
251
- "content modified" . to_owned ( ) ,
252
- ) ) ,
266
+ Err ( _cancelled) => {
267
+ let error = on_cancelled ( ) ;
268
+ Task :: Response ( Response { id : req. id , result : None , error : Some ( error) } )
269
+ }
253
270
}
254
271
} ) ;
255
272
@@ -280,6 +297,14 @@ impl RequestDispatcher<'_> {
280
297
}
281
298
}
282
299
}
300
+
301
+ fn content_modified_error ( ) -> ResponseError {
302
+ ResponseError {
303
+ code : lsp_server:: ErrorCode :: ContentModified as i32 ,
304
+ message : "content modified" . to_owned ( ) ,
305
+ data : None ,
306
+ }
307
+ }
283
308
}
284
309
285
310
fn thread_result_to_response < R > (
0 commit comments