@@ -5,7 +5,7 @@ use std::{
55} ;
66
77use ide:: Cancelled ;
8- use lsp_server:: ExtractError ;
8+ use lsp_server:: { ExtractError , Response , ResponseError } ;
99use serde:: { de:: DeserializeOwned , Serialize } ;
1010use stdx:: thread:: ThreadIntent ;
1111
@@ -117,15 +117,20 @@ impl RequestDispatcher<'_> {
117117 }
118118 return self ;
119119 }
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+ )
121125 }
122126
123127 /// 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 > (
126130 & mut self ,
127131 f : fn ( GlobalStateSnapshot , R :: Params ) -> anyhow:: Result < R :: Result > ,
128132 default : impl FnOnce ( ) -> R :: Result ,
133+ on_cancelled : fn ( ) -> ResponseError ,
129134 ) -> & mut Self
130135 where
131136 R : lsp_types:: request:: Request <
@@ -141,7 +146,7 @@ impl RequestDispatcher<'_> {
141146 }
142147 return self ;
143148 }
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 )
145150 }
146151
147152 /// Dispatches a non-latency-sensitive request onto the thread pool. When the VFS is marked not
@@ -160,7 +165,11 @@ impl RequestDispatcher<'_> {
160165 }
161166 return self ;
162167 }
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+ )
164173 }
165174
166175 /// Dispatches a latency-sensitive request onto the thread pool. When the VFS is marked not
@@ -183,7 +192,11 @@ impl RequestDispatcher<'_> {
183192 }
184193 return self ;
185194 }
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+ )
187200 }
188201
189202 /// Formatting requests should never block on waiting a for task thread to open up, editors will wait
@@ -198,7 +211,11 @@ impl RequestDispatcher<'_> {
198211 R :: Params : DeserializeOwned + panic:: UnwindSafe + Send + fmt:: Debug ,
199212 R :: Result : Serialize ,
200213 {
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+ )
202219 }
203220
204221 pub ( crate ) fn finish ( & mut self ) {
@@ -217,6 +234,7 @@ impl RequestDispatcher<'_> {
217234 & mut self ,
218235 intent : ThreadIntent ,
219236 f : fn ( GlobalStateSnapshot , R :: Params ) -> anyhow:: Result < R :: Result > ,
237+ on_cancelled : fn ( ) -> ResponseError ,
220238 ) -> & mut Self
221239 where
222240 R : lsp_types:: request:: Request + ' static ,
@@ -245,11 +263,10 @@ impl RequestDispatcher<'_> {
245263 match thread_result_to_response :: < R > ( req. id . clone ( ) , result) {
246264 Ok ( response) => Task :: Response ( response) ,
247265 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+ }
253270 }
254271 } ) ;
255272
@@ -280,6 +297,14 @@ impl RequestDispatcher<'_> {
280297 }
281298 }
282299 }
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+ }
283308}
284309
285310fn thread_result_to_response < R > (
0 commit comments