Skip to content

Commit

Permalink
Make output console work again
Browse files Browse the repository at this point in the history
This uses a last processed index for adding new message that we didn't add yet, so we can keep the folded output items.
  • Loading branch information
RemcoSmitsDev committed Feb 21, 2025
1 parent 104980a commit dba8640
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
20 changes: 18 additions & 2 deletions crates/debugger_ui/src/session/running/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,24 @@ impl Console {
editor
});

let _subscriptions =
vec![cx.subscribe(&stack_frame_list, Self::handle_stack_frame_list_events)];
let _subscriptions = vec![
cx.subscribe(&stack_frame_list, Self::handle_stack_frame_list_events),
cx.observe_in(&session, window, |console, session, window, cx| {
let (output, last_processed_ix) = session.update(cx, |session, cx| {
(session.output(), session.last_processed_output())
});

if output.len() > last_processed_ix {
for event in &output[last_processed_ix..] {
console.add_message(event.clone(), window, cx);
}

session.update(cx, |session, cx| {
session.set_last_processed_output(output.len());
});
}
}),
];

Self {
session,
Expand Down
22 changes: 21 additions & 1 deletion crates/project/src/debugger/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ pub struct Session {
ignore_breakpoints: bool,
modules: Vec<dap::Module>,
loaded_sources: Vec<dap::Source>,
last_processed_output: usize,
output: Vec<dap::OutputEvent>,
threads: IndexMap<ThreadId, Thread>,
requests: HashMap<RequestSlot, Shared<Task<Option<()>>>>,
thread_states: ThreadStates,
Expand Down Expand Up @@ -550,6 +552,8 @@ impl Session {
capabilities,
thread_states: ThreadStates::default(),
ignore_breakpoints: false,
last_processed_output: 0,
output: Vec::default(),
requests: HashMap::default(),
modules: Vec::default(),
loaded_sources: Vec::default(),
Expand Down Expand Up @@ -578,6 +582,8 @@ impl Session {
breakpoint_store,
ignore_breakpoints,
thread_states: ThreadStates::default(),
last_processed_output: 0,
output: Vec::default(),
requests: HashMap::default(),
modules: Vec::default(),
loaded_sources: Vec::default(),
Expand Down Expand Up @@ -709,6 +715,18 @@ impl Session {
})
}

pub fn output(&self) -> Vec<dap::OutputEvent> {
self.output.iter().cloned().collect()
}

pub fn last_processed_output(&self) -> usize {
self.last_processed_output
}

pub fn set_last_processed_output(&mut self, last_processed_output: usize) {
self.last_processed_output = last_processed_output;
}

fn handle_stopped_event(&mut self, event: StoppedEvent, cx: &mut Context<Self>) {
// todo(debugger): We should query for all threads here if we don't get a thread id
// maybe in both cases too?
Expand Down Expand Up @@ -757,7 +775,9 @@ impl Session {
}
self.invalidate_state(&ThreadsCommand.into());
}
Events::Output(_event) => {}
Events::Output(event) => {
self.output.push(event);
}
Events::Breakpoint(_) => {}
Events::Module(_) => {
self.invalidate_state(&ModulesCommand.into());
Expand Down

0 comments on commit dba8640

Please sign in to comment.