diff --git a/crates/debugger_ui/src/session/running/console.rs b/crates/debugger_ui/src/session/running/console.rs index b3ab2c845fae2d..ba46d3af21c840 100644 --- a/crates/debugger_ui/src/session/running/console.rs +++ b/crates/debugger_ui/src/session/running/console.rs @@ -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, diff --git a/crates/project/src/debugger/session.rs b/crates/project/src/debugger/session.rs index 634bb2f2a3b039..119a04d9a877d0 100644 --- a/crates/project/src/debugger/session.rs +++ b/crates/project/src/debugger/session.rs @@ -414,6 +414,8 @@ pub struct Session { ignore_breakpoints: bool, modules: Vec, loaded_sources: Vec, + last_processed_output: usize, + output: Vec, threads: IndexMap, requests: HashMap>>>, thread_states: ThreadStates, @@ -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(), @@ -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(), @@ -709,6 +715,18 @@ impl Session { }) } + pub fn output(&self) -> Vec { + 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) { // todo(debugger): We should query for all threads here if we don't get a thread id // maybe in both cases too? @@ -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());