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
32 ui::{Button, Clickable, ContextMenu, Label, LabelCommon, PopoverMenu, h_flex},32 ui::{Button, Clickable, ContextMenu, Label, LabelCommon, PopoverMenu, h_flex},
33};33};
34 34
35#[derive(Debug, Copy, Clone, PartialEq, Eq)]
36enum View {
37 AdapterLogs,
38 RpcMessages,
39 InitializationSequence,
40}
41
35struct DapLogView {42struct DapLogView {
36 editor: Entity<Editor>,43 editor: Entity<Editor>,
37 focus_handle: FocusHandle,44 focus_handle: FocusHandle,
38 log_store: Entity<LogStore>,45 log_store: Entity<LogStore>,
39 editor_subscriptions: Vec<Subscription>,46 editor_subscriptions: Vec<Subscription>,
40 current_view: Option<(SessionId, LogKind)>,47 current_view: Option<(SessionId, View)>,
41 project: Entity<Project>,48 project: Entity<Project>,
42 _subscriptions: Vec<Subscription>,49 _subscriptions: Vec<Subscription>,
43}50}
@@ -77,6 +84,7 @@ struct DebugAdapterState { · 33 unmodified lines
77 id: SessionId,84 id: SessionId,
78 log_messages: VecDeque<SharedString>,85 log_messages: VecDeque<SharedString>,
79 rpc_messages: RpcMessages,86 rpc_messages: RpcMessages,
87 session_label: SharedString,
80 adapter_name: DebugAdapterName,88 adapter_name: DebugAdapterName,
81 has_adapter_logs: bool,89 has_adapter_logs: bool,
82 is_terminated: bool,90 is_terminated: bool,
@@ -121,12 +129,18 @@ impl MessageKind { · 38 unmodified lines
121}129}
122 130
123impl DebugAdapterState {131impl 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 {
125 Self {138 Self {
126 id,139 id,
127 log_messages: VecDeque::new(),140 log_messages: VecDeque::new(),
128 rpc_messages: RpcMessages::new(),141 rpc_messages: RpcMessages::new(),
129 adapter_name,142 adapter_name,
143 session_label,
130 has_adapter_logs,144 has_adapter_logs,
131 is_terminated: false,145 is_terminated: false,
132 }146 }
@@ -371,18 +385,21 @@ impl LogStore { · 238 unmodified lines
371 return None;385 return None;
372 };386 };
373 387
374 let (adapter_name, has_adapter_logs) = session.read_with(cx, |session, _| {388 let (adapter_name, session_label, has_adapter_logs) =
375 (389 session.read_with(cx, |session, _| {
376 session.adapter(),390 (
377 session391 session.adapter(),
378 .adapter_client()392 session.label(),
379 .map_or(false, |client| client.has_adapter_logs()),393 session
380 )394 .adapter_client()
381 });395 .map_or(false, |client| client.has_adapter_logs()),
396 )
397 });
382 398
383 state.insert(DebugAdapterState::new(399 state.insert(DebugAdapterState::new(
384 id.session_id,400 id.session_id,
385 adapter_name,401 adapter_name,
402 session_label,
386 has_adapter_logs,403 has_adapter_logs,
387 ));404 ));
388 405
@@ -506,12 +523,13 @@ impl Render for DapLogToolbarItemView { · 117 unmodified lines
506 current_client523 current_client
507 .map(|sub_item| {524 .map(|sub_item| {
508 Cow::Owned(format!(525 Cow::Owned(format!(
509 "{} ({}) - {}",526 "{} - {} - {}",
510 sub_item.adapter_name,527 sub_item.adapter_name,
511 sub_item.session_id.0,528 sub_item.session_label,
512 match sub_item.selected_entry {529 match sub_item.selected_entry {
513 LogKind::Adapter => ADAPTER_LOGS,530 View::AdapterLogs => ADAPTER_LOGS,
514 LogKind::Rpc => RPC_MESSAGES,531 View::RpcMessages => RPC_MESSAGES,
532 View::InitializationSequence => INITIALIZATION_SEQUENCE,
515 }533 }
516 ))534 ))
517 })535 })
@@ -529,8 +547,8 @@ impl Render for DapLogToolbarItemView { · 11 unmodified lines
529 .pl_2()547 .pl_2()
530 .child(548 .child(
531 Label::new(format!(549 Label::new(format!(
532 "{}. {}",550 "{} - {}",
533 row.session_id.0, row.adapter_name,551 row.adapter_name, row.session_label
534 ))552 ))
535 .color(workspace::ui::Color::Muted),553 .color(workspace::ui::Color::Muted),
536 )554 )
@@ -669,9 +687,16 @@ impl DapLogView { · 132 unmodified lines
669 687
670 let events_subscriptions = cx.subscribe(&log_store, |log_view, _, event, cx| match event {688 let events_subscriptions = cx.subscribe(&log_store, |log_view, _, event, cx| match event {
671 Event::NewLogEntry { id, entry, kind } => {689 Event::NewLogEntry { id, entry, kind } => {
672 if log_view.current_view == Some((id.session_id, *kind))690 let is_current_view = match (log_view.current_view, *kind) {
673 && log_view.project == *id.project691 (Some((i, View::AdapterLogs)), LogKind::Adapter)
674 {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 {
675 log_view.editor.update(cx, |editor, cx| {700 log_view.editor.update(cx, |editor, cx| {
676 editor.set_read_only(false);701 editor.set_read_only(false);
677 let last_point = editor.buffer().read(cx).len(cx);702 let last_point = editor.buffer().read(cx).len(cx);
@@ -768,10 +793,11 @@ impl DapLogView { · 90 unmodified lines
768 .map(|state| DapMenuItem {793 .map(|state| DapMenuItem {
769 session_id: state.id,794 session_id: state.id,
770 adapter_name: state.adapter_name.clone(),795 adapter_name: state.adapter_name.clone(),
796 session_label: state.session_label.clone(),
771 has_adapter_logs: state.has_adapter_logs,797 has_adapter_logs: state.has_adapter_logs,
772 selected_entry: self798 selected_entry: self
773 .current_view799 .current_view
774 .map_or(LogKind::Adapter, |(_, kind)| kind),800 .map_or(View::AdapterLogs, |(_, kind)| kind),
775 })801 })
776 .collect::<Vec<_>>()802 .collect::<Vec<_>>()
777 })803 })
@@ -789,7 +815,7 @@ impl DapLogView { · 11 unmodified lines
789 .map(|state| log_contents(state.iter().cloned()))815 .map(|state| log_contents(state.iter().cloned()))
790 });816 });
791 if let Some(rpc_log) = rpc_log {817 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));
793 let (editor, editor_subscriptions) = Self::editor_for_logs(rpc_log, window, cx);819 let (editor, editor_subscriptions) = Self::editor_for_logs(rpc_log, window, cx);
794 let language = self.project.read(cx).languages().language_for_name("JSON");820 let language = self.project.read(cx).languages().language_for_name("JSON");
795 editor821 editor
@@ -830,7 +856,7 @@ impl DapLogView { · 34 unmodified lines
830 .map(|state| log_contents(state.iter().cloned()))856 .map(|state| log_contents(state.iter().cloned()))
831 });857 });
832 if let Some(message_log) = message_log {858 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));
834 let (editor, editor_subscriptions) = Self::editor_for_logs(message_log, window, cx);860 let (editor, editor_subscriptions) = Self::editor_for_logs(message_log, window, cx);
835 editor861 editor
836 .read(cx)862 .read(cx)
@@ -859,7 +885,7 @@ impl DapLogView { · 22 unmodified lines
859 .map(|state| log_contents(state.iter().cloned()))885 .map(|state| log_contents(state.iter().cloned()))
860 });886 });
861 if let Some(rpc_log) = rpc_log {887 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));
863 let (editor, editor_subscriptions) = Self::editor_for_logs(rpc_log, window, cx);889 let (editor, editor_subscriptions) = Self::editor_for_logs(rpc_log, window, cx);
864 let language = self.project.read(cx).languages().language_for_name("JSON");890 let language = self.project.read(cx).languages().language_for_name("JSON");
865 editor891 editor
@@ -899,11 +925,12 @@ fn log_contents(lines: impl Iterator<Item = SharedString>) -> String { · 33 unmodified lines
899}925}
900 926
901#[derive(Clone, PartialEq)]927#[derive(Clone, PartialEq)]
902pub(crate) struct DapMenuItem {928struct DapMenuItem {
903 pub session_id: SessionId,929 session_id: SessionId,
904 pub adapter_name: DebugAdapterName,930 session_label: SharedString,
905 pub has_adapter_logs: bool,931 adapter_name: DebugAdapterName,
906 pub selected_entry: LogKind,932 has_adapter_logs: bool,
933 selected_entry: View,
907}934}
908 935
909const ADAPTER_LOGS: &str = "Adapter Logs";936const 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
11use rpc::proto;11use rpc::proto;
12use running::RunningState;12use running::RunningState;
13use std::{cell::OnceCell, sync::OnceLock};13use std::{cell::OnceCell, sync::OnceLock};
14use ui::{Indicator, Tooltip, prelude::*};14use ui::{Indicator, prelude::*};
15use util::truncate_and_trailoff;15use util::truncate_and_trailoff;
16use workspace::{16use workspace::{
17 CollaboratorId, FollowableItem, ViewId, Workspace,17 CollaboratorId, FollowableItem, ViewId, Workspace,
@@ -158,7 +158,6 @@ impl DebugSession { · 140 unmodified lines
158 158
159 h_flex()159 h_flex()
160 .id("session-label")160 .id("session-label")
161 .tooltip(Tooltip::text(format!("Session {}", self.session_id(cx).0,)))
162 .ml(depth * px(16.0))161 .ml(depth * px(16.0))
163 .gap_2()162 .gap_2()
164 .when_some(icon, |this, indicator| this.child(indicator))163 .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