@@ -230,68 +230,66 @@ fn start_default_prettier(
230
230
cx : & mut ModelContext < ' _ , Project > ,
231
231
) -> Task < anyhow:: Result < PrettierTask > > {
232
232
cx. spawn ( |project, mut cx| async move {
233
- loop {
234
- let installation_task = project. update ( & mut cx, |project, _| {
235
- match & project. default_prettier . prettier {
236
- PrettierInstallation :: NotInstalled {
237
- installation_task, ..
238
- } => ControlFlow :: Continue ( installation_task. clone ( ) ) ,
239
- PrettierInstallation :: Installed ( default_prettier) => {
240
- ControlFlow :: Break ( default_prettier. clone ( ) )
241
- }
233
+ let installation_task = project. update ( & mut cx, |project, _| {
234
+ match & project. default_prettier . prettier {
235
+ PrettierInstallation :: NotInstalled {
236
+ installation_task, ..
237
+ } => ControlFlow :: Continue ( installation_task. clone ( ) ) ,
238
+ PrettierInstallation :: Installed ( default_prettier) => {
239
+ ControlFlow :: Break ( default_prettier. clone ( ) )
242
240
}
243
- } ) ?;
244
- match installation_task {
245
- ControlFlow :: Continue ( None ) => {
246
- anyhow:: bail!( "Default prettier is not installed and cannot be started" )
241
+ }
242
+ } ) ?;
243
+ match installation_task {
244
+ ControlFlow :: Continue ( None ) => {
245
+ anyhow:: bail!( "Default prettier is not installed and cannot be started" )
246
+ }
247
+ ControlFlow :: Continue ( Some ( installation_task) ) => {
248
+ log:: info!( "Waiting for default prettier to install" ) ;
249
+ if let Err ( e) = installation_task. await {
250
+ project. update ( & mut cx, |project, _| {
251
+ if let PrettierInstallation :: NotInstalled {
252
+ installation_task,
253
+ attempts,
254
+ ..
255
+ } = & mut project. default_prettier . prettier
256
+ {
257
+ * installation_task = None ;
258
+ * attempts += 1 ;
259
+ }
260
+ } ) ?;
261
+ anyhow:: bail!(
262
+ "Cannot start default prettier due to its installation failure: {e:#}"
263
+ ) ;
247
264
}
248
- ControlFlow :: Continue ( Some ( installation_task) ) => {
249
- log:: info!( "Waiting for default prettier to install" ) ;
250
- if let Err ( e) = installation_task. await {
251
- project. update ( & mut cx, |project, _| {
252
- if let PrettierInstallation :: NotInstalled {
253
- installation_task,
254
- attempts,
255
- ..
256
- } = & mut project. default_prettier . prettier
257
- {
258
- * installation_task = None ;
259
- * attempts += 1 ;
260
- }
261
- } ) ?;
262
- anyhow:: bail!(
263
- "Cannot start default prettier due to its installation failure: {e:#}"
264
- ) ;
265
- }
265
+ let new_default_prettier = project. update ( & mut cx, |project, cx| {
266
+ let new_default_prettier =
267
+ start_prettier ( node, DEFAULT_PRETTIER_DIR . clone ( ) , worktree_id, cx) ;
268
+ project. default_prettier . prettier =
269
+ PrettierInstallation :: Installed ( PrettierInstance {
270
+ attempt : 0 ,
271
+ prettier : Some ( new_default_prettier. clone ( ) ) ,
272
+ } ) ;
273
+ new_default_prettier
274
+ } ) ?;
275
+ return Ok ( new_default_prettier) ;
276
+ }
277
+ ControlFlow :: Break ( instance) => match instance. prettier {
278
+ Some ( instance) => return Ok ( instance) ,
279
+ None => {
266
280
let new_default_prettier = project. update ( & mut cx, |project, cx| {
267
281
let new_default_prettier =
268
282
start_prettier ( node, DEFAULT_PRETTIER_DIR . clone ( ) , worktree_id, cx) ;
269
283
project. default_prettier . prettier =
270
284
PrettierInstallation :: Installed ( PrettierInstance {
271
- attempt : 0 ,
285
+ attempt : instance . attempt + 1 ,
272
286
prettier : Some ( new_default_prettier. clone ( ) ) ,
273
287
} ) ;
274
288
new_default_prettier
275
289
} ) ?;
276
290
return Ok ( new_default_prettier) ;
277
291
}
278
- ControlFlow :: Break ( instance) => match instance. prettier {
279
- Some ( instance) => return Ok ( instance) ,
280
- None => {
281
- let new_default_prettier = project. update ( & mut cx, |project, cx| {
282
- let new_default_prettier =
283
- start_prettier ( node, DEFAULT_PRETTIER_DIR . clone ( ) , worktree_id, cx) ;
284
- project. default_prettier . prettier =
285
- PrettierInstallation :: Installed ( PrettierInstance {
286
- attempt : instance. attempt + 1 ,
287
- prettier : Some ( new_default_prettier. clone ( ) ) ,
288
- } ) ;
289
- new_default_prettier
290
- } ) ?;
291
- return Ok ( new_default_prettier) ;
292
- }
293
- } ,
294
- }
292
+ } ,
295
293
}
296
294
} )
297
295
}
0 commit comments