Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly refetch/invalidate stackframes/scopes/variables #55

Merged
merged 6 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions crates/debugger_tools/src/dap_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,8 @@ impl LogStore {
io_kind: IoKind,
message: &str,
cx: &mut ModelContext<Self>,
) -> Option<()> {
) {
self.add_debug_client_message(client_id, io_kind, message.to_string(), cx);

Some(())
}

fn on_adapter_log(
Expand All @@ -148,10 +146,8 @@ impl LogStore {
io_kind: IoKind,
message: &str,
cx: &mut ModelContext<Self>,
) -> Option<()> {
) {
self.add_debug_client_log(client_id, io_kind, message.to_string(), cx);

Some(())
}

pub fn add_project(&mut self, project: &Model<Project>, cx: &mut ModelContext<Self>) {
Expand Down
4 changes: 1 addition & 3 deletions crates/debugger_ui/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ impl Console {
console.add_message(&response.result, cx);

console.variable_list.update(cx, |variable_list, cx| {
variable_list
.refetch_existing_variables(cx)
.detach_and_log_err(cx);
variable_list.invalidate(cx);
})
})
})
Expand Down
43 changes: 26 additions & 17 deletions crates/debugger_ui/src/stack_frame_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct StackFrameList {
workspace: WeakView<Workspace>,
client_id: DebugAdapterClientId,
_subscriptions: Vec<Subscription>,
fetch_stack_frames_task: Option<Task<Result<()>>>,
}

impl StackFrameList {
Expand Down Expand Up @@ -65,6 +66,7 @@ impl StackFrameList {
client_id: *client_id,
workspace: workspace.clone(),
dap_store: dap_store.clone(),
fetch_stack_frames_task: None,
stack_frames: Default::default(),
current_stack_frame_id: Default::default(),
}
Expand All @@ -86,31 +88,34 @@ impl StackFrameList {
) {
match event {
Stopped { go_to_stack_frame } => {
self.fetch_stack_frames(*go_to_stack_frame, cx)
.detach_and_log_err(cx);
self.fetch_stack_frames(*go_to_stack_frame, cx);
}
_ => {}
}
}

fn fetch_stack_frames(
&self,
go_to_stack_frame: bool,
cx: &mut ViewContext<Self>,
) -> Task<Result<()>> {
pub fn invalidate(&mut self, cx: &mut ViewContext<Self>) {
self.fetch_stack_frames(true, cx);
}

fn fetch_stack_frames(&mut self, go_to_stack_frame: bool, cx: &mut ViewContext<Self>) {
let task = self.dap_store.update(cx, |store, cx| {
store.stack_frames(&self.client_id, self.thread_id, cx)
});

cx.spawn(|this, mut cx| async move {
self.fetch_stack_frames_task = Some(cx.spawn(|this, mut cx| async move {
let mut stack_frames = task.await?;

let task = this.update(&mut cx, |this, cx| {
std::mem::swap(&mut this.stack_frames, &mut stack_frames);

let previous_stack_frame_id = this.current_stack_frame_id;
if let Some(stack_frame) = this.stack_frames.first() {
this.current_stack_frame_id = stack_frame.id;
cx.emit(StackFrameListEvent::SelectedStackFrameChanged);

if previous_stack_frame_id != this.current_stack_frame_id {
cx.emit(StackFrameListEvent::SelectedStackFrameChanged);
}
}

this.list.reset(this.stack_frames.len());
Expand All @@ -129,8 +134,10 @@ impl StackFrameList {
task.await?;
}

Ok(())
})
this.update(&mut cx, |this, _| {
this.fetch_stack_frames_task.take();
})
}));
}

pub fn go_to_stack_frame(&mut self, cx: &mut ViewContext<Self>) -> Task<Result<()>> {
Expand All @@ -151,19 +158,21 @@ impl StackFrameList {
return Task::ready(Err(anyhow!("Project path not found")));
};

self.dap_store.update(cx, |store, cx| {
store.set_active_debug_line(&project_path, row, column, cx);
});

cx.spawn({
let workspace = self.workspace.clone();
move |_, mut cx| async move {
move |this, mut cx| async move {
let task = workspace.update(&mut cx, |workspace, cx| {
workspace.open_path_preview(project_path, None, false, true, cx)
workspace.open_path_preview(project_path.clone(), None, false, true, cx)
})?;

let editor = task.await?.downcast::<Editor>().unwrap();

this.update(&mut cx, |this, cx| {
this.dap_store.update(cx, |store, cx| {
store.set_active_debug_line(&project_path, row, column, cx);
})
})?;

workspace.update(&mut cx, |_, cx| {
editor.update(cx, |editor, cx| editor.go_to_active_debug_line(cx))
})
Expand Down
Loading
Loading