aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-12-05 05:43:34 +0000
committerBlaž Hrastnik2021-12-06 00:32:21 +0000
commit2b4de41bf0e0fc7d276e99f6359c9062df65473d (patch)
tree1c3e85b3a4a2d9762b98ba763030511224514153 /helix-term/src
parentd5d1a9b1ae3bb7e02c86d0785e74f90358a048c6 (diff)
dap: Reply to RunInTerminal
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/application.rs268
1 files changed, 142 insertions, 126 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 8dd5f47a..c2daaa6b 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -320,161 +320,177 @@ impl Application {
pub async fn handle_debugger_message(&mut self, payload: helix_dap::Payload) {
use crate::commands::dap::{breakpoints_changed, resume_application, select_thread_id};
+ use dap::requests::RunInTerminal;
use helix_dap::{events, Event};
+ let debugger = match self.editor.debugger.as_mut() {
+ Some(debugger) => debugger,
+ None => return,
+ };
match payload {
- Payload::Event(ev) => {
- let debugger = match self.editor.debugger.as_mut() {
- Some(debugger) => debugger,
- None => return,
- };
- match ev {
- Event::Stopped(events::Stopped {
- thread_id,
- description,
- text,
- reason,
- all_threads_stopped,
- ..
- }) => {
- let all_threads_stopped = all_threads_stopped.unwrap_or_default();
-
- if all_threads_stopped {
- if let Ok(threads) = debugger.threads().await {
- for thread in threads {
- fetch_stack_trace(debugger, thread.id).await;
- }
- select_thread_id(
- &mut self.editor,
- thread_id.unwrap_or_default(),
- false,
- )
- .await;
+ Payload::Event(ev) => match ev {
+ Event::Stopped(events::Stopped {
+ thread_id,
+ description,
+ text,
+ reason,
+ all_threads_stopped,
+ ..
+ }) => {
+ let all_threads_stopped = all_threads_stopped.unwrap_or_default();
+
+ if all_threads_stopped {
+ if let Ok(threads) = debugger.threads().await {
+ for thread in threads {
+ fetch_stack_trace(debugger, thread.id).await;
}
- } else if let Some(thread_id) = thread_id {
- debugger.thread_states.insert(thread_id, reason.clone()); // TODO: dap uses "type" || "reason" here
-
- // whichever thread stops is made "current" (if no previously selected thread).
- select_thread_id(&mut self.editor, thread_id, false).await;
+ select_thread_id(
+ &mut self.editor,
+ thread_id.unwrap_or_default(),
+ false,
+ )
+ .await;
}
+ } else if let Some(thread_id) = thread_id {
+ debugger.thread_states.insert(thread_id, reason.clone()); // TODO: dap uses "type" || "reason" here
- let scope = match thread_id {
- Some(id) => format!("Thread {}", id),
- None => "Target".to_owned(),
- };
+ // whichever thread stops is made "current" (if no previously selected thread).
+ select_thread_id(&mut self.editor, thread_id, false).await;
+ }
- let mut status = format!("{} stopped because of {}", scope, reason);
- if let Some(desc) = description {
- status.push_str(&format!(" {}", desc));
- }
- if let Some(text) = text {
- status.push_str(&format!(" {}", text));
- }
- if all_threads_stopped {
- status.push_str(" (all threads stopped)");
- }
+ let scope = match thread_id {
+ Some(id) => format!("Thread {}", id),
+ None => "Target".to_owned(),
+ };
- self.editor.set_status(status);
+ let mut status = format!("{} stopped because of {}", scope, reason);
+ if let Some(desc) = description {
+ status.push_str(&format!(" {}", desc));
}
- Event::Continued(events::Continued { thread_id, .. }) => {
- debugger
- .thread_states
- .insert(thread_id, "running".to_owned());
- if debugger.thread_id == Some(thread_id) {
- resume_application(debugger)
- }
+ if let Some(text) = text {
+ status.push_str(&format!(" {}", text));
}
- Event::Thread(_) => {
- // TODO: update thread_states, make threads request
+ if all_threads_stopped {
+ status.push_str(" (all threads stopped)");
}
- Event::Breakpoint(events::Breakpoint { reason, breakpoint }) => {
- match &reason[..] {
- "new" => {
- if let Some(source) = breakpoint.source {
- self.editor
- .breakpoints
- .entry(source.path.unwrap()) // TODO: no unwraps
- .or_default()
- .push(Breakpoint {
- id: breakpoint.id,
- verified: breakpoint.verified,
- message: breakpoint.message,
- line: breakpoint.line.unwrap().saturating_sub(1), // TODO: no unwrap
- column: breakpoint.column,
- ..Default::default()
- });
- }
+
+ self.editor.set_status(status);
+ }
+ Event::Continued(events::Continued { thread_id, .. }) => {
+ debugger
+ .thread_states
+ .insert(thread_id, "running".to_owned());
+ if debugger.thread_id == Some(thread_id) {
+ resume_application(debugger)
+ }
+ }
+ Event::Thread(_) => {
+ // TODO: update thread_states, make threads request
+ }
+ Event::Breakpoint(events::Breakpoint { reason, breakpoint }) => {
+ match &reason[..] {
+ "new" => {
+ if let Some(source) = breakpoint.source {
+ self.editor
+ .breakpoints
+ .entry(source.path.unwrap()) // TODO: no unwraps
+ .or_default()
+ .push(Breakpoint {
+ id: breakpoint.id,
+ verified: breakpoint.verified,
+ message: breakpoint.message,
+ line: breakpoint.line.unwrap().saturating_sub(1), // TODO: no unwrap
+ column: breakpoint.column,
+ ..Default::default()
+ });
}
- "changed" => {
- for breakpoints in self.editor.breakpoints.values_mut() {
- if let Some(i) =
- breakpoints.iter().position(|b| b.id == breakpoint.id)
- {
- breakpoints[i].verified = breakpoint.verified;
- breakpoints[i].message = breakpoint.message.clone();
- breakpoints[i].line =
- breakpoint.line.unwrap().saturating_sub(1); // TODO: no unwrap
- breakpoints[i].column = breakpoint.column;
- }
+ }
+ "changed" => {
+ for breakpoints in self.editor.breakpoints.values_mut() {
+ if let Some(i) =
+ breakpoints.iter().position(|b| b.id == breakpoint.id)
+ {
+ breakpoints[i].verified = breakpoint.verified;
+ breakpoints[i].message = breakpoint.message.clone();
+ breakpoints[i].line =
+ breakpoint.line.unwrap().saturating_sub(1); // TODO: no unwrap
+ breakpoints[i].column = breakpoint.column;
}
}
- "removed" => {
- for breakpoints in self.editor.breakpoints.values_mut() {
- if let Some(i) =
- breakpoints.iter().position(|b| b.id == breakpoint.id)
- {
- breakpoints.remove(i);
- }
+ }
+ "removed" => {
+ for breakpoints in self.editor.breakpoints.values_mut() {
+ if let Some(i) =
+ breakpoints.iter().position(|b| b.id == breakpoint.id)
+ {
+ breakpoints.remove(i);
}
}
- reason => {
- warn!("Unknown breakpoint event: {}", reason);
- }
+ }
+ reason => {
+ warn!("Unknown breakpoint event: {}", reason);
}
}
- Event::Output(events::Output {
- category, output, ..
- }) => {
- let prefix = match category {
- Some(category) => {
- if &category == "telemetry" {
- return;
- }
- format!("Debug ({}):", category)
+ }
+ Event::Output(events::Output {
+ category, output, ..
+ }) => {
+ let prefix = match category {
+ Some(category) => {
+ if &category == "telemetry" {
+ return;
}
- None => "Debug:".to_owned(),
- };
-
- log::info!("{}", output);
- self.editor.set_status(format!("{} {}", prefix, output));
- }
- Event::Initialized => {
- // send existing breakpoints
- for (path, breakpoints) in &mut self.editor.breakpoints {
- // TODO: call futures in parallel, await all
- let _ = breakpoints_changed(debugger, path.clone(), breakpoints);
+ format!("Debug ({}):", category)
}
- // TODO: fetch breakpoints (in case we're attaching)
+ None => "Debug:".to_owned(),
+ };
- if debugger.configuration_done().await.is_ok() {
- self.editor
- .set_status("Debugged application started".to_owned());
- }; // TODO: do we need to handle error?
- }
- ev => {
- log::warn!("Unhandled event {:?}", ev);
- return; // return early to skip render
+ log::info!("{}", output);
+ self.editor.set_status(format!("{} {}", prefix, output));
+ }
+ Event::Initialized => {
+ // send existing breakpoints
+ for (path, breakpoints) in &mut self.editor.breakpoints {
+ // TODO: call futures in parallel, await all
+ let _ = breakpoints_changed(debugger, path.clone(), breakpoints);
}
+ // TODO: fetch breakpoints (in case we're attaching)
+
+ if debugger.configuration_done().await.is_ok() {
+ self.editor
+ .set_status("Debugged application started".to_owned());
+ }; // TODO: do we need to handle error?
}
- }
+ ev => {
+ log::warn!("Unhandled event {:?}", ev);
+ return; // return early to skip render
+ }
+ },
Payload::Response(_) => unreachable!(),
Payload::Request(request) => match request.command.as_str() {
- dap::requests::RunInTerminal::COMMAND => {
+ RunInTerminal::COMMAND => {
let arguments: dap::requests::RunInTerminalArguments =
serde_json::from_value(request.arguments.unwrap_or_default()).unwrap();
// TODO: no unwrap
- // TODO: dap reply
+ // TODO: handle cwd
+ let process = std::process::Command::new("tmux")
+ .arg("split-window")
+ .arg(arguments.args.join(" ")) // TODO: first arg is wrong, it uses current dir
+ .spawn()
+ .unwrap();
+
+ let _ = debugger
+ .reply(
+ request.seq,
+ dap::requests::RunInTerminal::COMMAND,
+ serde_json::to_value(dap::requests::RunInTerminalResponse {
+ process_id: Some(process.id()),
+ shell_process_id: None,
+ })
+ .map_err(|e| e.into()),
+ )
+ .await;
}
_ => log::error!("DAP reverse request not implemented: {:?}", request),
},