History

DAP log view improvements (#34311)

Now DAP logs show the label of each session which makes it much easier to pick out the right one. Also "initialization sequence" now shows up correctly when that view is selected. Release Notes: - N/A ---------

Julia Ryan committed 1 year ago

Commit c3edc2c1 parent 625a4b92 files · +56 −30Browse files

Unified · Split

2 files
  1. crates/debugger_tools/src/dap_log.rs +55 −28
  2. crates/debugger_ui/src/session.rs +1 −2
crates/debugger_tools/src/dap_log.rs+55−28
@@ -32,12 +32,19 @@ use workspace::{ · 31 unmodified lines
3232 ui::{Button, Clickable, ContextMenu, Label, LabelCommon, PopoverMenu, h_flex},
3333 };
3434
35+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
36+enum View {
37+ AdapterLogs,
38+ RpcMessages,
39+ InitializationSequence,
40+}
41+
3542 struct DapLogView {
3643 editor: Entity<Editor>,
3744 focus_handle: FocusHandle,
3845 log_store: Entity<LogStore>,
3946 editor_subscriptions: Vec<Subscription>,
40− current_view: Option<(SessionId, LogKind)>,
47+ current_view: Option<(SessionId, View)>,
4148 project: Entity<Project>,
4249 _subscriptions: Vec<Subscription>,
4350 }
@@ -77,6 +84,7 @@ struct DebugAdapterState { · 33 unmodified lines
7784 id: SessionId,
7885 log_messages: VecDeque<SharedString>,
7986 rpc_messages: RpcMessages,
87+ session_label: SharedString,
8088 adapter_name: DebugAdapterName,
8189 has_adapter_logs: bool,
8290 is_terminated: bool,
@@ -121,12 +129,18 @@ impl MessageKind { · 38 unmodified lines
121129 }
122130
123131 impl DebugAdapterState {
124− fn new(id: SessionId, adapter_name: DebugAdapterName, has_adapter_logs: bool) -> Self {
132+ fn new(
133+ id: SessionId,
134+ adapter_name: DebugAdapterName,
135+ session_label: SharedString,
136+ has_adapter_logs: bool,
137+ ) -> Self {
125138 Self {
126139 id,
127140 log_messages: VecDeque::new(),
128141 rpc_messages: RpcMessages::new(),
129142 adapter_name,
143+ session_label,
130144 has_adapter_logs,
131145 is_terminated: false,
132146 }
@@ -371,18 +385,21 @@ impl LogStore { · 238 unmodified lines
371385 return None;
372386 };
373387
374− let (adapter_name, has_adapter_logs) = session.read_with(cx, |session, _| {
375− (
376− session.adapter(),
377− session
378− .adapter_client()
379− .map_or(false, |client| client.has_adapter_logs()),
380− )
381− });
388+ let (adapter_name, session_label, has_adapter_logs) =
389+ session.read_with(cx, |session, _| {
390+ (
391+ session.adapter(),
392+ session.label(),
393+ session
394+ .adapter_client()
395+ .map_or(false, |client| client.has_adapter_logs()),
396+ )
397+ });
382398
383399 state.insert(DebugAdapterState::new(
384400 id.session_id,
385401 adapter_name,
402+ session_label,
386403 has_adapter_logs,
387404 ));
388405
@@ -506,12 +523,13 @@ impl Render for DapLogToolbarItemView { · 117 unmodified lines
506523 current_client
507524 .map(|sub_item| {
508525 Cow::Owned(format!(
509− "{} ({}) - {}",
526+ "{} - {} - {}",
510527 sub_item.adapter_name,
511− sub_item.session_id.0,
528+ sub_item.session_label,
512529 match sub_item.selected_entry {
513− LogKind::Adapter => ADAPTER_LOGS,
514− LogKind::Rpc => RPC_MESSAGES,
530+ View::AdapterLogs => ADAPTER_LOGS,
531+ View::RpcMessages => RPC_MESSAGES,
532+ View::InitializationSequence => INITIALIZATION_SEQUENCE,
515533 }
516534 ))
517535 })
@@ -529,8 +547,8 @@ impl Render for DapLogToolbarItemView { · 11 unmodified lines
529547 .pl_2()
530548 .child(
531549 Label::new(format!(
532− "{}. {}",
533− row.session_id.0, row.adapter_name,
550+ "{} - {}",
551+ row.adapter_name, row.session_label
534552 ))
535553 .color(workspace::ui::Color::Muted),
536554 )
@@ -669,9 +687,16 @@ impl DapLogView { · 132 unmodified lines
669687
670688 let events_subscriptions = cx.subscribe(&log_store, |log_view, _, event, cx| match event {
671689 Event::NewLogEntry { id, entry, kind } => {
672− if log_view.current_view == Some((id.session_id, *kind))
673− && log_view.project == *id.project
674− {
690+ let is_current_view = match (log_view.current_view, *kind) {
691+ (Some((i, View::AdapterLogs)), LogKind::Adapter)
692+ | (Some((i, View::RpcMessages)), LogKind::Rpc)
693+ if i == id.session_id =>
694+ {
695+ log_view.project == *id.project
696+ }
697+ _ => false,
698+ };
699+ if is_current_view {
675700 log_view.editor.update(cx, |editor, cx| {
676701 editor.set_read_only(false);
677702 let last_point = editor.buffer().read(cx).len(cx);
@@ -768,10 +793,11 @@ impl DapLogView { · 90 unmodified lines
768793 .map(|state| DapMenuItem {
769794 session_id: state.id,
770795 adapter_name: state.adapter_name.clone(),
796+ session_label: state.session_label.clone(),
771797 has_adapter_logs: state.has_adapter_logs,
772798 selected_entry: self
773799 .current_view
774− .map_or(LogKind::Adapter, |(_, kind)| kind),
800+ .map_or(View::AdapterLogs, |(_, kind)| kind),
775801 })
776802 .collect::<Vec<_>>()
777803 })
@@ -789,7 +815,7 @@ impl DapLogView { · 11 unmodified lines
789815 .map(|state| log_contents(state.iter().cloned()))
790816 });
791817 if let Some(rpc_log) = rpc_log {
792− self.current_view = Some((id.session_id, LogKind::Rpc));
818+ self.current_view = Some((id.session_id, View::RpcMessages));
793819 let (editor, editor_subscriptions) = Self::editor_for_logs(rpc_log, window, cx);
794820 let language = self.project.read(cx).languages().language_for_name("JSON");
795821 editor
@@ -830,7 +856,7 @@ impl DapLogView { · 34 unmodified lines
830856 .map(|state| log_contents(state.iter().cloned()))
831857 });
832858 if let Some(message_log) = message_log {
833− self.current_view = Some((id.session_id, LogKind::Adapter));
859+ self.current_view = Some((id.session_id, View::AdapterLogs));
834860 let (editor, editor_subscriptions) = Self::editor_for_logs(message_log, window, cx);
835861 editor
836862 .read(cx)
@@ -859,7 +885,7 @@ impl DapLogView { · 22 unmodified lines
859885 .map(|state| log_contents(state.iter().cloned()))
860886 });
861887 if let Some(rpc_log) = rpc_log {
862− self.current_view = Some((id.session_id, LogKind::Rpc));
888+ self.current_view = Some((id.session_id, View::InitializationSequence));
863889 let (editor, editor_subscriptions) = Self::editor_for_logs(rpc_log, window, cx);
864890 let language = self.project.read(cx).languages().language_for_name("JSON");
865891 editor
@@ -899,11 +925,12 @@ fn log_contents(lines: impl Iterator<Item = SharedString>) -> String { · 33 unmodified lines
899925 }
900926
901927 #[derive(Clone, PartialEq)]
902−pub(crate) struct DapMenuItem {
903− pub session_id: SessionId,
904− pub adapter_name: DebugAdapterName,
905− pub has_adapter_logs: bool,
906− pub selected_entry: LogKind,
928+struct DapMenuItem {
929+ session_id: SessionId,
930+ session_label: SharedString,
931+ adapter_name: DebugAdapterName,
932+ has_adapter_logs: bool,
933+ selected_entry: View,
907934 }
908935
909936 const ADAPTER_LOGS: &str = "Adapter Logs";
crates/debugger_ui/src/session.rs+1−2
@@ -11,7 +11,7 @@ use project::worktree_store::WorktreeStore; · 10 unmodified lines
1111 use rpc::proto;
1212 use running::RunningState;
1313 use std::{cell::OnceCell, sync::OnceLock};
14−use ui::{Indicator, Tooltip, prelude::*};
14+use ui::{Indicator, prelude::*};
1515 use util::truncate_and_trailoff;
1616 use workspace::{
1717 CollaboratorId, FollowableItem, ViewId, Workspace,
@@ -158,7 +158,6 @@ impl DebugSession { · 140 unmodified lines
158158
159159 h_flex()
160160 .id("session-label")
161− .tooltip(Tooltip::text(format!("Session {}", self.session_id(cx).0,)))
162161 .ml(depth * px(16.0))
163162 .gap_2()
164163 .when_some(icon, |this, indicator| this.child(indicator))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t