@@ -152,133 +152,123 @@ impl DebugPanel {
152
152
}
153
153
}
154
154
155
- pub fn go_to_stack_frame (
156
- stack_frame : & StackFrame ,
155
+ pub async fn go_to_stack_frame (
156
+ workspace : WeakView < Workspace > ,
157
+ stack_frame : StackFrame ,
157
158
client : Arc < DebugAdapterClient > ,
158
159
clear_highlights : bool ,
159
- cx : & mut ViewContext < Self > ,
160
- ) -> Task < Result < ( ) > > {
160
+ mut cx : AsyncWindowContext ,
161
+ ) -> Result < ( ) > {
161
162
let path = stack_frame. clone ( ) . source . unwrap ( ) . path . unwrap ( ) . clone ( ) ;
162
163
let row = ( stack_frame. line . saturating_sub ( 1 ) ) as u32 ;
163
164
let column = ( stack_frame. column . saturating_sub ( 1 ) ) as u32 ;
164
165
165
- cx. spawn ( move |this, mut cx| async move {
166
- if clear_highlights {
167
- // TODO:
168
- // this.update(&mut cx, |this, cx| this.remove_highlights(client, cx))?
169
- // .await?;
170
- }
166
+ if clear_highlights {
167
+ Self :: remove_highlights ( workspace. clone ( ) , client, cx. clone ( ) ) . await ?;
168
+ }
171
169
172
- let task = this. update ( & mut cx, |this, cx| {
173
- this. workspace . update ( cx, |workspace, cx| {
174
- let project_path = workspace. project ( ) . read_with ( cx, |project, cx| {
175
- project. project_path_for_absolute_path ( & Path :: new ( & path) , cx)
176
- } ) ;
170
+ let task = workspace. update ( & mut cx, |workspace, cx| {
171
+ let project_path = workspace. project ( ) . read_with ( cx, |project, cx| {
172
+ project. project_path_for_absolute_path ( & Path :: new ( & path) , cx)
173
+ } ) ;
177
174
178
- if let Some ( project_path) = project_path {
179
- workspace. open_path_preview ( project_path, None , false , true , cx)
180
- } else {
181
- Task :: ready ( Err ( anyhow:: anyhow!(
182
- "No project path found for path: {}" ,
183
- path
184
- ) ) )
185
- }
186
- } )
187
- } ) ??;
188
-
189
- let editor = task. await ?. downcast :: < Editor > ( ) . unwrap ( ) ;
190
-
191
- this. update ( & mut cx, |this, cx| {
192
- this. workspace . update ( cx, |_, cx| {
193
- editor. update ( cx, |editor, cx| {
194
- editor. go_to_line :: < DebugCurrentRowHighlight > (
195
- row,
196
- column,
197
- Some ( cx. theme ( ) . colors ( ) . editor_highlighted_line_background ) ,
198
- cx,
199
- ) ;
200
- } )
201
- } )
202
- } ) ??;
175
+ if let Some ( project_path) = project_path {
176
+ workspace. open_path_preview ( project_path, None , false , true , cx)
177
+ } else {
178
+ Task :: ready ( Err ( anyhow:: anyhow!(
179
+ "No project path found for path: {}" ,
180
+ path
181
+ ) ) )
182
+ }
183
+ } ) ?;
203
184
204
- anyhow:: Ok ( ( ) )
185
+ let editor = task. await ?. downcast :: < Editor > ( ) . unwrap ( ) ;
186
+
187
+ workspace. update ( & mut cx, |_, cx| {
188
+ editor. update ( cx, |editor, cx| {
189
+ editor. go_to_line :: < DebugCurrentRowHighlight > (
190
+ row,
191
+ column,
192
+ Some ( cx. theme ( ) . colors ( ) . editor_highlighted_line_background ) ,
193
+ cx,
194
+ ) ;
195
+ } )
205
196
} )
206
197
}
207
198
208
- fn remove_highlights (
199
+ async fn remove_highlights (
200
+ workspace : WeakView < Workspace > ,
209
201
client : Arc < DebugAdapterClient > ,
210
- cx : & mut ViewContext < Self > ,
211
- ) -> Task < Result < ( ) > > {
202
+ cx : AsyncWindowContext ,
203
+ ) -> Result < ( ) > {
212
204
let mut tasks = Vec :: new ( ) ;
213
205
for thread_state in client. thread_states ( ) . values ( ) {
214
206
for stack_frame in thread_state. stack_frames . clone ( ) {
215
- tasks. push ( Self :: remove_editor_highlight ( & stack_frame, cx) ) ;
207
+ tasks. push ( Self :: remove_editor_highlight (
208
+ workspace. clone ( ) ,
209
+ stack_frame,
210
+ cx. clone ( ) ,
211
+ ) ) ;
216
212
}
217
213
}
218
214
219
- if tasks. is_empty ( ) {
220
- return Task :: ready ( Ok ( ( ) ) ) ;
221
- }
222
-
223
- cx. spawn ( |_, _| async move {
215
+ if !tasks. is_empty ( ) {
224
216
try_join_all ( tasks) . await ?;
217
+ }
225
218
226
- anyhow:: Ok ( ( ) )
227
- } )
219
+ anyhow:: Ok ( ( ) )
228
220
}
229
221
230
- fn remove_highlights_for_thread (
222
+ async fn remove_highlights_for_thread (
223
+ workspace : WeakView < Workspace > ,
231
224
client : Arc < DebugAdapterClient > ,
232
225
thread_id : u64 ,
233
- cx : & mut ViewContext < Self > ,
234
- ) -> Task < Result < ( ) > > {
226
+ cx : AsyncWindowContext ,
227
+ ) -> Result < ( ) > {
235
228
let mut tasks = Vec :: new ( ) ;
236
229
if let Some ( thread_state) = client. thread_states ( ) . get ( & thread_id) {
237
230
for stack_frame in thread_state. stack_frames . clone ( ) {
238
- tasks. push ( Self :: remove_editor_highlight ( & stack_frame, cx) ) ;
231
+ tasks. push ( Self :: remove_editor_highlight (
232
+ workspace. clone ( ) ,
233
+ stack_frame. clone ( ) ,
234
+ cx. clone ( ) ,
235
+ ) ) ;
239
236
}
240
237
}
241
238
242
- if tasks. is_empty ( ) {
243
- return Task :: ready ( Ok ( ( ) ) ) ;
244
- }
245
-
246
- cx. spawn ( |_, _| async move {
239
+ if !tasks. is_empty ( ) {
247
240
try_join_all ( tasks) . await ?;
241
+ }
248
242
249
- anyhow:: Ok ( ( ) )
250
- } )
243
+ anyhow:: Ok ( ( ) )
251
244
}
252
245
253
- fn remove_editor_highlight (
254
- stack_frame : & StackFrame ,
255
- cx : & mut ViewContext < Self > ,
256
- ) -> Task < Result < ( ) > > {
246
+ async fn remove_editor_highlight (
247
+ workspace : WeakView < Workspace > ,
248
+ stack_frame : StackFrame ,
249
+ mut cx : AsyncWindowContext ,
250
+ ) -> Result < ( ) > {
257
251
let path = stack_frame. clone ( ) . source . unwrap ( ) . path . unwrap ( ) . clone ( ) ;
258
252
259
- cx. spawn ( |this, mut cx| async move {
260
- let task = this. update ( & mut cx, |this, cx| {
261
- this. workspace . update ( cx, |workspace, cx| {
262
- let project_path = workspace. project ( ) . read_with ( cx, |project, cx| {
263
- project. project_path_for_absolute_path ( & Path :: new ( & path) , cx)
264
- } ) ;
253
+ let task = workspace. update ( & mut cx, |workspace, cx| {
254
+ let project_path = workspace. project ( ) . read_with ( cx, |project, cx| {
255
+ project. project_path_for_absolute_path ( & Path :: new ( & path) , cx)
256
+ } ) ;
265
257
266
- if let Some ( project_path) = project_path {
267
- workspace. open_path ( project_path, None , false , cx)
268
- } else {
269
- Task :: ready ( Err ( anyhow:: anyhow!(
270
- "No project path found for path: {}" ,
271
- path
272
- ) ) )
273
- }
274
- } )
275
- } ) ??;
258
+ if let Some ( project_path) = project_path {
259
+ workspace. open_path ( project_path, None , false , cx)
260
+ } else {
261
+ Task :: ready ( Err ( anyhow:: anyhow!(
262
+ "No project path found for path: {}" ,
263
+ path
264
+ ) ) )
265
+ }
266
+ } ) ?;
276
267
277
- let editor = task. await ?. downcast :: < Editor > ( ) . unwrap ( ) ;
268
+ let editor = task. await ?. downcast :: < Editor > ( ) . unwrap ( ) ;
278
269
279
- editor. update ( & mut cx, |editor, _| {
280
- editor. clear_row_highlights :: < DebugCurrentRowHighlight > ( ) ;
281
- } )
270
+ editor. update ( & mut cx, |editor, _| {
271
+ editor. clear_row_highlights :: < DebugCurrentRowHighlight > ( ) ;
282
272
} )
283
273
}
284
274
@@ -394,12 +384,18 @@ impl DebugPanel {
394
384
if let Some ( item) = this. pane . read ( cx) . active_item ( ) {
395
385
if let Some ( pane) = item. downcast :: < DebugPanelItem > ( ) {
396
386
if pane. read ( cx) . thread_id ( ) == thread_id {
397
- return Self :: go_to_stack_frame (
398
- & current_stack_frame,
399
- client. clone ( ) ,
400
- true ,
401
- cx,
402
- ) ;
387
+ let workspace = this. workspace . clone ( ) ;
388
+ let client = client. clone ( ) ;
389
+ return cx. spawn ( |_, cx| async move {
390
+ Self :: go_to_stack_frame (
391
+ workspace,
392
+ current_stack_frame. clone ( ) ,
393
+ client,
394
+ true ,
395
+ cx,
396
+ )
397
+ . await
398
+ } ) ;
403
399
}
404
400
}
405
401
}
@@ -429,16 +425,17 @@ impl DebugPanel {
429
425
client. update_thread_state_status ( thread_id. clone ( ) , ThreadStatus :: Ended ) ;
430
426
431
427
// TODO: we want to figure out for witch clients/threads we should remove the highlights
432
- // cx.spawn({
433
- // let client = client.clone();
434
- // |this, mut cx| async move {
435
- // this.update(&mut cx, |_, cx| {
436
- // Self::remove_highlights_for_thread(client, thread_id, cx)
437
- // })?
438
- // .await
439
- // }
440
- // })
441
- // .detach_and_log_err(cx);
428
+ cx. spawn ( {
429
+ let client = client. clone ( ) ;
430
+ |this, mut cx| async move {
431
+ let workspace = this. update ( & mut cx, |this, _| this. workspace . clone ( ) ) ?;
432
+
433
+ Self :: remove_highlights_for_thread ( workspace, client, thread_id, cx) . await ?;
434
+
435
+ anyhow:: Ok ( ( ) )
436
+ }
437
+ } )
438
+ . detach_and_log_err ( cx) ;
442
439
}
443
440
444
441
cx. emit ( DebugPanelEvent :: Thread ( ( * client_id, event. clone ( ) ) ) ) ;
@@ -452,12 +449,12 @@ impl DebugPanel {
452
449
) {
453
450
let restart_args = event. clone ( ) . and_then ( |e| e. restart ) ;
454
451
let client = this. debug_client_by_id ( * client_id, cx) ;
452
+ let workspace = this. workspace . clone ( ) ;
455
453
456
- cx. spawn ( |this , mut cx| async move {
454
+ cx. spawn ( |_ , cx| async move {
457
455
let should_restart = restart_args. is_some ( ) ;
458
456
459
- this. update ( & mut cx, |_, cx| Self :: remove_highlights ( client. clone ( ) , cx) ) ?
460
- . await ?;
457
+ Self :: remove_highlights ( workspace, client. clone ( ) , cx) . await ?;
461
458
462
459
client
463
460
. request :: < Disconnect > ( DisconnectArguments {
0 commit comments