@@ -95,45 +95,8 @@ impl RequestDispatcher<'_> {
9595 self
9696 }
9797
98- /// Dispatches a non-latency-sensitive request onto the thread pool
99- /// without retrying it if it panics.
100- pub ( crate ) fn on_no_retry < R > (
101- & mut self ,
102- f : fn ( GlobalStateSnapshot , R :: Params ) -> anyhow:: Result < R :: Result > ,
103- ) -> & mut Self
104- where
105- R : lsp_types:: request:: Request + ' static ,
106- R :: Params : DeserializeOwned + panic:: UnwindSafe + Send + fmt:: Debug ,
107- R :: Result : Serialize ,
108- {
109- let ( req, params, panic_context) = match self . parse :: < R > ( ) {
110- Some ( it) => it,
111- None => return self ,
112- } ;
113-
114- self . global_state . task_pool . handle . spawn ( ThreadIntent :: Worker , {
115- let world = self . global_state . snapshot ( ) ;
116- move || {
117- let result = panic:: catch_unwind ( move || {
118- let _pctx = stdx:: panic_context:: enter ( panic_context) ;
119- f ( world, params)
120- } ) ;
121- match thread_result_to_response :: < R > ( req. id . clone ( ) , result) {
122- Ok ( response) => Task :: Response ( response) ,
123- Err ( _) => Task :: Response ( lsp_server:: Response :: new_err (
124- req. id ,
125- lsp_server:: ErrorCode :: ContentModified as i32 ,
126- "content modified" . to_owned ( ) ,
127- ) ) ,
128- }
129- }
130- } ) ;
131-
132- self
133- }
134-
13598 /// Dispatches a non-latency-sensitive request onto the thread pool.
136- pub ( crate ) fn on < R > (
99+ pub ( crate ) fn on < const ALLOW_RETRYING : bool , R > (
137100 & mut self ,
138101 f : fn ( GlobalStateSnapshot , R :: Params ) -> anyhow:: Result < R :: Result > ,
139102 ) -> & mut Self
@@ -142,11 +105,11 @@ impl RequestDispatcher<'_> {
142105 R :: Params : DeserializeOwned + panic:: UnwindSafe + Send + fmt:: Debug ,
143106 R :: Result : Serialize ,
144107 {
145- self . on_with_thread_intent :: < true , R > ( ThreadIntent :: Worker , f)
108+ self . on_with_thread_intent :: < true , ALLOW_RETRYING , R > ( ThreadIntent :: Worker , f)
146109 }
147110
148111 /// Dispatches a latency-sensitive request onto the thread pool.
149- pub ( crate ) fn on_latency_sensitive < R > (
112+ pub ( crate ) fn on_latency_sensitive < const ALLOW_RETRYING : bool , R > (
150113 & mut self ,
151114 f : fn ( GlobalStateSnapshot , R :: Params ) -> anyhow:: Result < R :: Result > ,
152115 ) -> & mut Self
@@ -155,7 +118,7 @@ impl RequestDispatcher<'_> {
155118 R :: Params : DeserializeOwned + panic:: UnwindSafe + Send + fmt:: Debug ,
156119 R :: Result : Serialize ,
157120 {
158- self . on_with_thread_intent :: < true , R > ( ThreadIntent :: LatencySensitive , f)
121+ self . on_with_thread_intent :: < true , ALLOW_RETRYING , R > ( ThreadIntent :: LatencySensitive , f)
159122 }
160123
161124 /// Formatting requests should never block on waiting a for task thread to open up, editors will wait
@@ -170,7 +133,7 @@ impl RequestDispatcher<'_> {
170133 R :: Params : DeserializeOwned + panic:: UnwindSafe + Send + fmt:: Debug ,
171134 R :: Result : Serialize ,
172135 {
173- self . on_with_thread_intent :: < false , R > ( ThreadIntent :: LatencySensitive , f)
136+ self . on_with_thread_intent :: < false , false , R > ( ThreadIntent :: LatencySensitive , f)
174137 }
175138
176139 pub ( crate ) fn finish ( & mut self ) {
@@ -185,7 +148,7 @@ impl RequestDispatcher<'_> {
185148 }
186149 }
187150
188- fn on_with_thread_intent < const MAIN_POOL : bool , R > (
151+ fn on_with_thread_intent < const MAIN_POOL : bool , const ALLOW_RETRYING : bool , R > (
189152 & mut self ,
190153 intent : ThreadIntent ,
191154 f : fn ( GlobalStateSnapshot , R :: Params ) -> anyhow:: Result < R :: Result > ,
@@ -215,7 +178,12 @@ impl RequestDispatcher<'_> {
215178 } ) ;
216179 match thread_result_to_response :: < R > ( req. id . clone ( ) , result) {
217180 Ok ( response) => Task :: Response ( response) ,
218- Err ( _) => Task :: Retry ( req) ,
181+ Err ( _cancelled) if ALLOW_RETRYING => Task :: Retry ( req) ,
182+ Err ( _cancelled) => Task :: Response ( lsp_server:: Response :: new_err (
183+ req. id ,
184+ lsp_server:: ErrorCode :: ContentModified as i32 ,
185+ "content modified" . to_owned ( ) ,
186+ ) ) ,
219187 }
220188 } ) ;
221189
0 commit comments