Skip to content

Commit

Permalink
restart dap
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhou121 committed Feb 12, 2023
1 parent 62e992e commit f8923a8
Show file tree
Hide file tree
Showing 18 changed files with 662 additions and 199 deletions.
1 change: 1 addition & 0 deletions defaults/settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ name = ""
"debug_small" = "debug-alt-small.svg"
"debug_restart" = "debug-restart.svg"
"debug_continue" = "debug-continue.svg"
"debug_pause" = "debug-pause.svg"
"debug_stop" = "debug-stop.svg"
"start" = "debug-start.svg"
"run_errors" = "run-errors.svg"
Expand Down
1 change: 1 addition & 0 deletions icons/codicons/debug-pause.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 3 additions & 5 deletions lapce-data/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use lapce_core::{
};
use lapce_rpc::{
buffer::BufferId,
dap_types::{DapId, RunDebugConfig, ThreadId},
dap_types::{DapId, RunDebugConfig, StackFrame, Stopped, ThreadId},
file::FileNodeItem,
plugin::{PluginId, VoltID, VoltInfo, VoltMetadata},
source_control::DiffInfo,
Expand Down Expand Up @@ -1058,14 +1058,12 @@ pub enum LapceUICommand {
},
DapStopped {
dap_id: DapId,
thread_id: ThreadId,
stopped: Stopped,
stack_frames: HashMap<ThreadId, Vec<StackFrame>>,
},
DapContinued {
dap_id: DapId,
},
DapTerminated {
dap_id: DapId,
},
}

/// This can't be an `FnOnce` because we only ever get a reference to
Expand Down
1 change: 1 addition & 0 deletions lapce-data/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ impl LapceIcons {
pub const DEBUG_SMALL: &str = "debug_small";
pub const DEBUG_RESTART: &str = "debug_restart";
pub const DEBUG_CONTINUE: &str = "debug_continue";
pub const DEBUG_PAUSE: &str = "debug_pause";
pub const DEBUG_STOP: &str = "debug_stop";
pub const START: &str = "start";
pub const RUN_ERRORS: &str = "run_errors";
Expand Down
31 changes: 12 additions & 19 deletions lapce-data/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,16 +1541,16 @@ impl LapceTabData {
));
}
LapceWorkbenchCommand::RunAndDebugRestart => {
if let Some(active_terminal) =
Arc::make_mut(&mut self.terminal).get_active_debug_terminal_mut()
if self
.terminal
.debug
.active_term
.and_then(|term_id| {
Arc::make_mut(&mut self.terminal)
.restart_run_debug(term_id, &self.config)
})
.is_none()
{
Arc::make_mut(active_terminal).restart_run_debug(&self.config);
let _ = ctx.get_external_handle().submit_command(
LAPCE_UI_COMMAND,
LapceUICommand::Focus,
Target::Widget(active_terminal.widget_id),
);
} else {
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::RunPalette(Some(PaletteType::RunAndDebug)),
Expand All @@ -1559,15 +1559,8 @@ impl LapceTabData {
}
}
LapceWorkbenchCommand::RunAndDebugStop => {
if let Some(active_terminal) =
Arc::make_mut(&mut self.terminal).get_active_debug_terminal_mut()
{
Arc::make_mut(active_terminal).stop_run_debug();
let _ = ctx.get_external_handle().submit_command(
LAPCE_UI_COMMAND,
LapceUICommand::Focus,
Target::Widget(active_terminal.widget_id),
);
if let Some(term_id) = self.terminal.debug.active_term {
Arc::make_mut(&mut self.terminal).stop_run_debug(term_id);
}
}
LapceWorkbenchCommand::PaletteWorkspace => {
Expand Down Expand Up @@ -2335,7 +2328,7 @@ impl LapceTabData {
) {
let terminal = Arc::make_mut(&mut self.terminal);
let term_id = if let Some(terminal) =
terminal.get_stopped_run_debug_terminal_mut(mode, &config.name)
terminal.get_stopped_run_debug_terminal_mut(mode, config)
{
Arc::make_mut(terminal).new_process(
Some(RunDebugProcess {
Expand Down
39 changes: 37 additions & 2 deletions lapce-data/src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{fmt::Display, path::Path, time::Instant};
use std::{collections::HashMap, fmt::Display, path::Path, time::Instant};

use druid::WidgetId;
use lapce_rpc::{
dap_types::{DapId, RunDebugConfig, ThreadId},
dap_types::{DapId, RunDebugConfig, StackFrame, Stopped, ThreadId},
terminal::TermId,
};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -34,6 +34,7 @@ pub enum RunDebugAction {
#[derive(Clone, Debug)]
pub enum DebugAction {
Continue,
Pause,
Restart,
Stop,
Close,
Expand Down Expand Up @@ -74,12 +75,19 @@ pub fn run_configs(workspace: Option<&Path>) -> Option<RunDebugConfigs> {
Some(configs)
}

#[derive(Clone)]
pub struct StackTraceData {
pub expanded: bool,
pub frames: Vec<StackFrame>,
}

#[derive(Clone)]
pub struct DapData {
pub term_id: TermId,
pub dap_id: DapId,
pub stopped: bool,
pub thread_id: Option<ThreadId>,
pub stack_frames: im::HashMap<ThreadId, StackTraceData>,
}

impl DapData {
Expand All @@ -89,7 +97,34 @@ impl DapData {
dap_id,
stopped: false,
thread_id: None,
stack_frames: im::HashMap::new(),
}
}

pub fn stopped(
&mut self,
stopped: &Stopped,
stack_frames: &HashMap<ThreadId, Vec<StackFrame>>,
) {
self.stopped = true;
if self.thread_id.is_none() {
self.thread_id = Some(stopped.thread_id.unwrap_or_default());
}
for (thread_id, frames) in stack_frames {
if let Some(current) = self.stack_frames.get_mut(thread_id) {
current.frames = frames.to_owned();
} else {
self.stack_frames.insert(
*thread_id,
StackTraceData {
expanded: true,
frames: frames.to_owned(),
},
);
}
}
self.stack_frames
.retain(|thread_id, _| stack_frames.contains_key(thread_id));
}
}

Expand Down
19 changes: 10 additions & 9 deletions lapce-data/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,18 @@ impl CoreHandler for LapceProxy {
log::log!(level, "{}", message);
}
}
DapStopped { dap_id, thread_id } => {
DapStopped {
dap_id,
stopped,
stack_frames,
} => {
let _ = self.event_sink.submit_command(
LAPCE_UI_COMMAND,
LapceUICommand::DapStopped { dap_id, thread_id },
LapceUICommand::DapStopped {
dap_id,
stopped,
stack_frames,
},
Target::Widget(self.tab_id),
);
}
Expand All @@ -333,13 +341,6 @@ impl CoreHandler for LapceProxy {
Target::Widget(self.tab_id),
);
}
DapTerminated { dap_id } => {
let _ = self.event_sink.submit_command(
LAPCE_UI_COMMAND,
LapceUICommand::DapTerminated { dap_id },
Target::Widget(self.tab_id),
);
}
}
}

Expand Down
117 changes: 85 additions & 32 deletions lapce-data/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use lapce_core::{
register::Clipboard,
};
use lapce_rpc::{
dap_types::RunDebugConfig,
dap_types::{DapId, RunDebugConfig},
terminal::{self, TermId},
};
use parking_lot::Mutex;
Expand Down Expand Up @@ -51,6 +51,7 @@ pub struct TerminalPanelData {
pub active: usize,
pub debug: Arc<RunDebugData>,
pub proxy: Arc<LapceProxy>,
pub event_sink: ExtEventSink,
}

impl TerminalPanelData {
Expand All @@ -65,7 +66,7 @@ impl TerminalPanelData {
worksapce,
proxy.clone(),
config,
event_sink,
event_sink.clone(),
run_debug,
);
let tabs_order = Arc::new(vec![split.split_id]);
Expand All @@ -79,6 +80,7 @@ impl TerminalPanelData {
active: 0,
debug,
proxy,
event_sink,
}
}

Expand Down Expand Up @@ -149,6 +151,11 @@ impl TerminalPanelData {
None
}

pub fn get_active_debug_terminal(&self) -> Option<&Arc<LapceTerminalData>> {
let term_id = self.debug.active_term?;
self.get_terminal(&term_id)
}

pub fn get_active_debug_terminal_mut(
&mut self,
) -> Option<&mut Arc<LapceTerminalData>> {
Expand All @@ -159,16 +166,24 @@ impl TerminalPanelData {
pub fn get_stopped_run_debug_terminal_mut(
&mut self,
mode: &RunDebugMode,
name: &str,
config: &RunDebugConfig,
) -> Option<&mut Arc<LapceTerminalData>> {
for (_, tab) in self.tabs.iter_mut() {
for (_, terminal) in tab.terminals.iter_mut() {
if let Some(run_debug) = terminal.run_debug.as_ref() {
if run_debug.stopped
&& run_debug.config.name == name
&& &run_debug.mode == mode
{
return Some(terminal);
if run_debug.stopped && &run_debug.mode == mode {
match run_debug.mode {
RunDebugMode::Run => {
if run_debug.config.name == config.name {
return Some(terminal);
}
}
RunDebugMode::Debug => {
if run_debug.config.dap_id == config.dap_id {
return Some(terminal);
}
}
}
}
}
}
Expand Down Expand Up @@ -207,6 +222,63 @@ impl TerminalPanelData {
processes
}

pub fn stop_run_debug(&mut self, term_id: TermId) -> Option<()> {
let terminal = self.get_terminal_mut(&term_id)?;
let terminal = Arc::make_mut(terminal);
let run_debug = terminal.run_debug.as_mut()?;
let widget_id = terminal.widget_id;

match run_debug.mode {
RunDebugMode::Run => {
run_debug.stopped = true;
self.proxy.proxy_rpc.terminal_close(term_id);
}
RunDebugMode::Debug => {
let dap_id = terminal.run_debug.as_ref()?.config.dap_id;
let dap = self.debug.daps.get(&dap_id)?;
self.proxy.proxy_rpc.dap_stop(dap.dap_id);
}
}

let _ = self.event_sink.submit_command(
LAPCE_UI_COMMAND,
LapceUICommand::Focus,
Target::Widget(widget_id),
);
Some(())
}

pub fn restart_run_debug(
&mut self,
term_id: TermId,
config: &LapceConfig,
) -> Option<()> {
let proxy = self.proxy.clone();
let terminal = self.get_terminal_mut(&term_id)?;
let terminal = Arc::make_mut(terminal);
let widget_id = terminal.widget_id;
let run_debug = terminal.run_debug.as_ref()?;
match run_debug.mode {
RunDebugMode::Run => {
let mut run_debug = run_debug.clone();
run_debug.stopped = false;
proxy.proxy_rpc.terminal_close(term_id);
terminal.new_process(Some(run_debug), config);
}
RunDebugMode::Debug => {
let dap_id = terminal.run_debug.as_ref()?.config.dap_id;
let dap = self.debug.daps.get(&dap_id)?;
proxy.proxy_rpc.dap_restart(dap.dap_id);
}
}
let _ = self.event_sink.submit_command(
LAPCE_UI_COMMAND,
LapceUICommand::Focus,
Target::Widget(widget_id),
);
Some(())
}

pub fn dap_continue(&self, term_id: TermId) -> Option<()> {
let terminal = self.get_terminal(&term_id)?;
let dap = self
Expand All @@ -215,17 +287,18 @@ impl TerminalPanelData {
.get(&terminal.run_debug.as_ref()?.config.dap_id)?;
let thread_id = dap.thread_id?;
self.proxy.proxy_rpc.dap_continue(dap.dap_id, thread_id);
None
Some(())
}

pub fn dap_stop(&self, term_id: TermId) -> Option<()> {
pub fn dap_pause(&self, term_id: TermId) -> Option<()> {
let terminal = self.get_terminal(&term_id)?;
let dap = self
.debug
.daps
.get(&terminal.run_debug.as_ref()?.config.dap_id)?;
self.proxy.proxy_rpc.dap_stop(dap.dap_id);
None
let thread_id = dap.thread_id?;
self.proxy.proxy_rpc.dap_pause(dap.dap_id, thread_id);
Some(())
}
}

Expand Down Expand Up @@ -833,26 +906,6 @@ impl LapceTerminalData {
raw
}

pub fn stop_run_debug(&mut self) {
let run_debug = match self.run_debug.as_mut() {
Some(run_debug) => run_debug,
None => return,
};
run_debug.stopped = true;
self.proxy.proxy_rpc.terminal_close(self.term_id);
}

pub fn restart_run_debug(&mut self, config: &LapceConfig) {
let run_debug = match self.run_debug.as_ref() {
Some(run_debug) => run_debug,
None => return,
};
let mut run_debug = run_debug.clone();
run_debug.stopped = false;
self.proxy.proxy_rpc.terminal_close(self.term_id);
self.new_process(Some(run_debug), config);
}

pub fn new_process(
&mut self,
run_debug: Option<RunDebugProcess>,
Expand Down
Loading

0 comments on commit f8923a8

Please sign in to comment.