Skip to content

Commit 0f3dd61

Browse files
authored
Allow context depth to be changed (#21)
1 parent 5c845cc commit 0f3dd61

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

src/app.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ pub struct App {
138138
pub counter: u16,
139139

140140
pub snapshot_notify: Arc<Notify>,
141+
pub context_depth: u8,
141142
}
142143

143144
impl App {
@@ -154,6 +155,7 @@ impl App {
154155
history: History::default(),
155156
client: Arc::new(Mutex::new(client)),
156157
counter: 0,
158+
context_depth: 4,
157159

158160
server_status: None,
159161
command_input: Input::default(),
@@ -277,6 +279,10 @@ impl App {
277279
AppEvent::ClientConnected(s) => {
278280
let mut client = self.client.lock().await;
279281
let response = client.deref_mut().connect(s).await?;
282+
client.feature_set(
283+
"max_depth",
284+
self.context_depth.to_string().as_str()
285+
).await?;
280286
self.is_connected = true;
281287
self.server_status = None;
282288
self.view_current = CurrentView::Session;
@@ -301,6 +307,14 @@ impl App {
301307
AppEvent::Run => {
302308
self.exec_continuation(AppEvent::Run).await;
303309
}
310+
AppEvent::ContextDepth(inc) => {
311+
let depth = self.context_depth as i8;
312+
self.context_depth = depth.wrapping_add(inc).max(0) as u8;
313+
self.client.lock().await.feature_set(
314+
"max_depth",
315+
self.context_depth.to_string().as_str()
316+
).await?;
317+
},
304318
AppEvent::ScrollSource(amount) => {
305319
self.session_view.source_scroll = self
306320
.session_view

src/dbgp/client.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ impl DbgpClient {
155155
}
156156
}
157157

158+
pub(crate) async fn feature_set(&mut self, feature: &str, value: &str) -> Result<()> {
159+
match self.command("feature_set", &mut vec!["-n",feature,"-v",value]).await? {
160+
Message::Response(r) => match r.command {
161+
CommandResponse::Unknown => Ok(()),
162+
_ => anyhow::bail!("Unexpected response"),
163+
},
164+
_ => anyhow::bail!("Unexpected response"),
165+
}
166+
}
167+
158168
pub(crate) async fn context_get(&mut self) -> Result<ContextGetResponse> {
159169
match self.command("context_get", &mut vec![]).await? {
160170
Message::Response(r) => match r.command {

src/event/input.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub enum AppEvent {
4444
ToggleFullscreen,
4545
ScrollStack(i16),
4646
PushInputPlurality(char),
47+
ContextDepth(i8),
4748
}
4849

4950
pub type EventSender = Sender<AppEvent>;

src/view/help.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Key mappings (prefix with number to repeat):
4343
[J] scroll down 10
4444
[k] scroll up
4545
[K] scroll up 10
46+
[+] increase context depth
47+
[-] decrease context depth
4648
[enter] toggle pane focus (full screen)
4749
4850
Legend:

src/view/session.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ impl View for SessionView {
4444
let next_event: Option<AppEvent> = match app.session_view.mode {
4545
SessionViewMode::Current => match input_event.code {
4646
KeyCode::Char(char) => match char {
47+
'+' => Some(AppEvent::ContextDepth(1)),
48+
'-' => Some(AppEvent::ContextDepth(-1)),
4749
'r' => Some(AppEvent::Run),
4850
'n' => Some(AppEvent::StepInto),
4951
'N' => Some(AppEvent::StepOver),
@@ -119,7 +121,7 @@ fn build_pane_widget(frame: &mut Frame, app: &App, pane: &Pane, area: Rect, inde
119121
Some(c) => c.source.filename.to_string(),
120122
None => "".to_string(),
121123
},
122-
ComponentType::Context => "Context".to_string(),
124+
ComponentType::Context => format!("Context({})", app.context_depth),
123125
ComponentType::Stack => "Stack".to_string(),
124126
})
125127
.style(

0 commit comments

Comments
 (0)