Skip to content

Commit

Permalink
Add output editor
Browse files Browse the repository at this point in the history
  • Loading branch information
RemcoSmitsDev committed Aug 4, 2024
1 parent e03cc4a commit 5a60145
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
18 changes: 13 additions & 5 deletions crates/debugger_ui/src/debugger_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use dap::requests::{Disconnect, Request, Scopes, StackTrace, StartDebugging, Var
use dap::transport::Payload;
use dap::{client::DebugAdapterClient, transport::Events};
use dap::{
Capabilities, ContinuedEvent, DisconnectArguments, ExitedEvent, Scope, ScopesArguments,
StackFrame, StackTraceArguments, StartDebuggingRequestArguments, StoppedEvent, TerminatedEvent,
ThreadEvent, ThreadEventReason, Variable, VariablesArguments,
Capabilities, ContinuedEvent, DisconnectArguments, ExitedEvent, OutputEvent, Scope,
ScopesArguments, StackFrame, StackTraceArguments, StartDebuggingRequestArguments, StoppedEvent,
TerminatedEvent, ThreadEvent, ThreadEventReason, Variable, VariablesArguments,
};
use editor::Editor;
use futures::future::try_join_all;
Expand All @@ -29,10 +29,10 @@ use workspace::{

enum DebugCurrentRowHighlight {}

#[derive(Debug)]
pub enum DebugPanelEvent {
Stopped((DebugAdapterClientId, StoppedEvent)),
Thread((DebugAdapterClientId, ThreadEvent)),
Output((DebugAdapterClientId, OutputEvent)),
}

actions!(debug_panel, [ToggleFocus]);
Expand Down Expand Up @@ -187,7 +187,7 @@ impl DebugPanel {
Events::Exited(event) => Self::handle_exited_event(client, event, cx),
Events::Terminated(event) => Self::handle_terminated_event(this, client, event, cx),
Events::Thread(event) => Self::handle_thread_event(client, event, cx),
Events::Output(_) => {}
Events::Output(event) => Self::handle_output_event(client, event, cx),
Events::Breakpoint(_) => {}
Events::Module(_) => {}
Events::LoadedSource(_) => {}
Expand Down Expand Up @@ -583,6 +583,14 @@ impl DebugPanel {
})
.detach_and_log_err(cx);
}

fn handle_output_event(
client: Arc<DebugAdapterClient>,
event: &OutputEvent,
cx: &mut ViewContext<Self>,
) {
cx.emit(DebugPanelEvent::Output((client.id(), event.clone())));
}
}

impl EventEmitter<PanelEvent> for DebugPanel {}
Expand Down
45 changes: 44 additions & 1 deletion crates/debugger_ui/src/debugger_panel_item.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::debugger_panel::{DebugPanel, DebugPanelEvent};
use anyhow::Result;
use dap::client::{DebugAdapterClient, DebugAdapterClientId, ThreadState, ThreadStatus};
use dap::{Scope, StackFrame, StoppedEvent, ThreadEvent, Variable};
use dap::{OutputEvent, Scope, StackFrame, StoppedEvent, ThreadEvent, Variable};
use editor::Editor;
use gpui::{
actions, list, AnyElement, AppContext, AsyncWindowContext, EventEmitter, FocusHandle,
FocusableView, ListState, Subscription, View, WeakView,
Expand All @@ -26,6 +27,7 @@ pub struct DebugPanelItem {
_subscriptions: Vec<Subscription>,
current_stack_frame_id: Option<u64>,
active_thread_item: ThreadItem,
output_editor: View<Editor>,
}

actions!(
Expand Down Expand Up @@ -62,14 +64,33 @@ impl DebugPanelItem {
DebugPanelEvent::Thread((client_id, event)) => {
Self::handle_thread_event(this, client_id, event, cx)
}
DebugPanelEvent::Output((client_id, event)) => {
Self::handle_output_event(this, client_id, event, cx)
}
};
}
})];

let output_editor = cx.new_view(|cx| {
let mut editor = Editor::multi_line(cx);
editor.move_to_end(&editor::actions::MoveToEnd, cx);
editor.set_placeholder_text("Debug adapter and script output", cx);
editor.set_read_only(true);
editor.set_show_inline_completions(false);
editor.set_searchable(true);
editor.set_auto_replace_emoji_shortcode(false);
editor.set_show_indent_guides(false, cx);
editor.set_autoindent(false);
editor.set_show_gutter(false, cx);
editor.set_show_line_numbers(false, cx);
editor
});

Self {
client,
thread_id,
focus_handle,
output_editor,
_subscriptions,
stack_frame_list,
current_stack_frame_id: None,
Expand Down Expand Up @@ -112,6 +133,25 @@ impl DebugPanelItem {

// TODO: handle thread event
}

fn handle_output_event(
this: &mut Self,
client_id: &DebugAdapterClientId,
event: &OutputEvent,
cx: &mut ViewContext<Self>,
) {
if Self::should_skip_event(this, client_id, this.thread_id) {
return;
}

this.output_editor.update(cx, |editor, cx| {
editor.set_read_only(false);
editor.insert(&event.output.as_str(), cx);
editor.set_read_only(true);

cx.notify();
});
}
}

impl EventEmitter<ItemEvent> for DebugPanelItem {}
Expand Down Expand Up @@ -614,6 +654,9 @@ impl Render for DebugPanelItem {
)
.when(*active_thread_item == ThreadItem::Variables, |this| {
this.child(self.render_scopes(cx))
})
.when(*active_thread_item == ThreadItem::Output, |this| {
this.child(self.output_editor.clone())
}),
)
.into_any()
Expand Down

0 comments on commit 5a60145

Please sign in to comment.