Skip to content

Commit

Permalink
WIP Get variable to send during variable list
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony-Eid committed Dec 9, 2024
1 parent f2575da commit c95993c
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 23 deletions.
4 changes: 3 additions & 1 deletion crates/dap/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
pub mod adapters;
pub mod client;
pub mod debugger_settings;
pub mod proto_conversions;
pub mod transport;

pub use dap_types::*;
pub mod debugger_settings;

#[cfg(any(test, feature = "test-support"))]
pub use adapters::FakeAdapter;
32 changes: 32 additions & 0 deletions crates/dap/src/proto_conversions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use client::proto::DapScope;

pub trait ProtoConversion {
type DapType;

fn to_proto(&self) -> Self::DapType;
fn from_proto(payload: Self::DapType) -> Self;
}

impl ProtoConversion for dap_types::Scope {
type DapType = DapScope;

fn to_proto(&self) -> Self::DapType {
Self::DapType {
name: self.name.clone(),
presentation_hint: Default::default(), //TODO Debugger Collab
variables_reference: self.variables_reference,
named_variables: self.named_variables,
indexed_variables: self.indexed_variables,
expensive: self.expensive,
source: None, //TODO Debugger Collab
line: self.line,
end_line: self.end_line,
column: self.column,
end_column: self.end_column,
}
}

fn from_proto(_payload: Self::DapType) -> Self {
todo!()
}
}
27 changes: 15 additions & 12 deletions crates/debugger_ui/src/debugger_panel_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::module_list::ModuleList;
use crate::stack_frame_list::{StackFrameList, StackFrameListEvent};
use crate::variable_list::VariableList;

use client::proto::{self, PeerId};
use anyhow::{anyhow, Result};
use dap::{
client::{DebugAdapterClientId, ThreadStatus},
debugger_settings::DebuggerSettings,
Expand All @@ -18,6 +18,7 @@ use gpui::{
View, WeakView,
};
use project::dap_store::DapStore;
use rpc::proto::{self, PeerId, SetDebuggerPanelItem};
use settings::Settings;
use ui::{prelude::*, Indicator, Tooltip, WindowContext};
use workspace::item;
Expand Down Expand Up @@ -201,6 +202,17 @@ impl DebugPanelItem {
}
}

pub(crate) fn set_from_proto(
&mut self,
state: &proto::view::DebugPanel,
cx: &mut ViewContext<Self>,
) {
if let Some(variable_list_state) = state.variable_list.as_ref() {
self.variable_list
.update(cx, |this, cx| this.set_from_proto(variable_list_state, cx));
}
}

pub fn update_thread_state_status(&mut self, status: ThreadStatus, cx: &mut ViewContext<Self>) {
self.thread_state.update(cx, |thread_state, cx| {
thread_state.status = status;
Expand Down Expand Up @@ -599,8 +611,6 @@ impl FollowableItem for DebugPanelItem {
}

fn to_state_proto(&self, cx: &WindowContext) -> Option<proto::view::Variant> {
dbg!("Into to state proto");

let thread_state = Some(self.thread_state.read_with(cx, |this, _| this.to_proto()));
let modules = self.module_list.read(cx).to_proto();
let variable_list = Some(self.variable_list.read(cx).to_proto());
Expand All @@ -623,18 +633,13 @@ impl FollowableItem for DebugPanelItem {
state: &mut Option<proto::view::Variant>,
cx: &mut WindowContext,
) -> Option<gpui::Task<gpui::Result<View<Self>>>> {
dbg!("In from state proto 3pm ish");
let proto::view::Variant::DebugPanel(_) = state.as_ref()? else {
dbg!(state.as_ref());
dbg!("In from state proto NONE case");
return None;
};
let Some(proto::view::Variant::DebugPanel(state)) = state.take() else {
unreachable!()
};

dbg!("from state proto with debug panel");

let (_project, debug_panel) = workspace.update(cx, |workspace, cx| {
Some((
workspace.project().clone(),
Expand All @@ -650,8 +655,9 @@ impl FollowableItem for DebugPanelItem {
)
});

debug_panel_item.update(cx, |debug_panel_item, _| {
debug_panel_item.update(cx, |debug_panel_item, cx| {
debug_panel_item.remote_id = Some(remote_id);
debug_panel_item.set_from_proto(&state, cx);
});

Some(Task::ready(Ok(debug_panel_item)))
Expand Down Expand Up @@ -680,12 +686,9 @@ impl FollowableItem for DebugPanelItem {
}

fn set_leader_peer_id(&mut self, _leader_peer_id: Option<PeerId>, _cx: &mut ViewContext<Self>) {
dbg!("set leader peer id");
}

fn to_follow_event(_event: &Self::Event) -> Option<workspace::item::FollowEvent> {
dbg!("to follow event");

None
}

Expand Down
93 changes: 87 additions & 6 deletions crates/debugger_ui/src/variable_list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use crate::stack_frame_list::{StackFrameList, StackFrameListEvent};
use anyhow::Result;
use dap::{client::DebugAdapterClientId, Scope, ScopePresentationHint, Variable};
use dap::{
client::DebugAdapterClientId,
proto_conversions::{self, ProtoConversion},
Scope, ScopePresentationHint, Variable,
};
use editor::{
actions::{self, SelectAll},
Editor, EditorEvent,
Expand Down Expand Up @@ -63,8 +67,25 @@ impl SetVariableState {
}
})?;

None
// SetVariableState { name: payload.name, scope, value: payload.value, stack_frame_id: payload.stack_frame_id, }
Some(SetVariableState {
name: payload.name,
scope,
value: payload.value,
stack_frame_id: payload.stack_frame_id,
evaluate_name: payload.evaluate_name.clone(),
parent_variables_reference: payload.parent_variables_reference,
})
}

fn to_proto(&self) -> proto::DebuggerSetVariableState {
proto::DebuggerSetVariableState {
name: self.name.clone(),
scope: Some(self.scope.to_proto()),
value: self.value.clone(),
stack_frame_id: self.stack_frame_id,
evaluate_name: self.evaluate_name.clone(),
parent_variables_reference: self.parent_variables_reference,
}
}
}

Expand All @@ -74,6 +95,38 @@ enum OpenEntry {
Variable { name: String, depth: usize },
}

impl OpenEntry {
pub(crate) fn from_proto(open_entry: &proto::VariableListOpenEntry) -> Option<Self> {
match open_entry.entry.as_ref()? {
proto::variable_list_open_entry::Entry::Scope(state) => Some(Self::Scope {
name: state.name.clone(),
}),
proto::variable_list_open_entry::Entry::Variable(state) => Some(Self::Variable {
name: state.name.clone(),
depth: state.depth as usize,
}),
}
}

pub(crate) fn to_proto(&self) -> proto::VariableListOpenEntry {
let entry = match self {
OpenEntry::Scope { name } => {
proto::variable_list_open_entry::Entry::Scope(proto::DebuggerOpenEntryScope {
name: name.clone(),
})
}
OpenEntry::Variable { name, depth } => {
proto::variable_list_open_entry::Entry::Variable(proto::DebuggerOpenEntryVariable {
name: name.clone(),
depth: *depth as u64,
})
}
};

proto::VariableListOpenEntry { entry: Some(entry) }
}
}

#[derive(Debug, Clone)]
pub enum VariableListEntry {
Scope(Scope),
Expand Down Expand Up @@ -133,6 +186,8 @@ impl ScopeVariableIndex {
}
}

// fn open_entries_from_proto(entries: &Vec<proto::VariableListOpenEntry>) -> Vec<OpenEntry>

type StackFrameId = u64;
type ScopeId = u64;

Expand Down Expand Up @@ -205,15 +260,41 @@ impl VariableList {
}

pub(crate) fn to_proto(&self) -> proto::DebuggerVariableList {
let open_entries = self.open_entries.iter().map(OpenEntry::to_proto).collect();
let set_variable_state = self
.set_variable_state
.as_ref()
.map(SetVariableState::to_proto);

proto::DebuggerVariableList {
open_entries: Default::default(),
open_entries,
scopes: Default::default(),
set_variable_state: Default::default(),
set_variable_state,
entries: Default::default(),
}
}

pub(crate) fn set_from_proto(&mut self, payload: &SetDebuggerPanelItem) {}
pub(crate) fn set_from_proto(
&mut self,
state: &proto::DebuggerVariableList,
cx: &mut ViewContext<Self>,
) {
self.open_entries = state
.open_entries
.iter()
.filter_map(OpenEntry::from_proto)
.collect();

self.set_variable_state = state
.set_variable_state
.clone()
.and_then(SetVariableState::from_proto);

dbg!("Setting from proto");
dbg!(&self.open_entries);
dbg!(&state.entries);
cx.notify();
}

fn handle_stack_frame_list_events(
&mut self,
Expand Down
4 changes: 0 additions & 4 deletions crates/workspace/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ impl<T: Item> ItemHandle for View<T> {
pane: View<Pane>,
cx: &mut ViewContext<Workspace>,
) {
dbg!("In added to pane");
let weak_item = self.downgrade();
let history = pane.read(cx).nav_history_for_item(self);
self.update(cx, |this, cx| {
Expand All @@ -616,7 +615,6 @@ impl<T: Item> ItemHandle for View<T> {

let mut send_follower_updates = None;
if let Some(item) = self.to_followable_item_handle(cx) {
dbg!(&item.type_id());
let is_project_item = item.is_project_item(cx);
let item = item.downgrade();

Expand All @@ -630,8 +628,6 @@ impl<T: Item> ItemHandle for View<T> {

workspace.update(&mut cx, |workspace, cx| {
let Some(item) = item.upgrade() else { return };
dbg!(&item.tab_tooltip_text(cx));
dbg!(pending_update.borrow());
workspace.update_followers(
is_project_item,
proto::update_followers::Variant::UpdateView(
Expand Down

0 comments on commit c95993c

Please sign in to comment.