diff options
author | Blaž Hrastnik | 2021-12-03 02:59:44 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-12-03 02:59:44 +0000 |
commit | 2dbf966293c7a92bd5eb6062c7033a20a207609f (patch) | |
tree | f0cbf36d0e69085ad0be083406d4ff0f0fca7c80 | |
parent | 0d73a4d23abf7b14321ec4db39a272372f923ad3 (diff) |
dap: Start working on runInTerminal support
-rw-r--r-- | helix-core/src/syntax.rs | 1 | ||||
-rw-r--r-- | helix-dap/src/client.rs | 2 | ||||
-rw-r--r-- | helix-term/src/application.rs | 249 | ||||
-rw-r--r-- | helix-term/src/commands/dap.rs | 26 | ||||
-rw-r--r-- | languages.toml | 6 |
5 files changed, 155 insertions, 129 deletions
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index f136ecd0..f1c399d2 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -114,6 +114,7 @@ pub enum DebugConfigCompletion { pub enum DebugArgumentValue { String(String), Array(Vec<String>), + Boolean(bool), } #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] diff --git a/helix-dap/src/client.rs b/helix-dap/src/client.rs index 427db18c..d83f25a6 100644 --- a/helix-dap/src/client.rs +++ b/helix-dap/src/client.rs @@ -244,7 +244,7 @@ impl Client { path_format: Some("path".to_owned()), supports_variable_type: Some(true), supports_variable_paging: Some(false), - supports_run_in_terminal_request: Some(false), + supports_run_in_terminal_request: Some(true), supports_memory_references: Some(false), supports_progress_reporting: Some(false), supports_invalidated_event: Some(false), diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index b6753ec5..522c4b73 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -321,147 +321,154 @@ 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 helix_dap::{events, Event}; - let debugger = match self.editor.debugger.as_mut() { - Some(debugger) => debugger, - None => return, - }; match payload { - 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; + 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; } - 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 + } 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; - } + // whichever thread stops is made "current" (if no previously selected thread). + select_thread_id(&mut self.editor, thread_id, false).await; + } - let scope = match thread_id { - Some(id) => format!("Thread {}", id), - None => "Target".to_owned(), - }; + let scope = match thread_id { + Some(id) => format!("Thread {}", id), + None => "Target".to_owned(), + }; - 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 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)"); + } - 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) + self.editor.set_status(status); } - } - 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() - }); + 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) } } - "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; - } - } + Event::Thread(_) => { + // TODO: update thread_states, make threads request } - "removed" => { - for breakpoints in self.editor.breakpoints.values_mut() { - if let Some(i) = breakpoints.iter().position(|b| b.id == breakpoint.id) - { - breakpoints.remove(i); + 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; + } + } + } + "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; + Event::Output(events::Output { + category, output, .. + }) => { + let prefix = match category { + Some(category) => { + if &category == "telemetry" { + return; + } + format!("Debug ({}):", category) } - format!("Debug ({}):", category) - } - None => "Debug:".to_owned(), - }; + 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); + log::info!("{}", output); + self.editor.set_status(format!("{} {}", prefix, output)); } - // TODO: fetch breakpoints (in case we're attaching) + 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 + 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(_) => todo!(), + Payload::Request(request) => unimplemented!("{:?}", request), } self.render(); } diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index b44be16c..f2be3a6c 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -251,29 +251,40 @@ pub fn dap_start_impl( // For param #0 replace {0} in args let pattern = format!("{{{}}}", i); value = match value { + // TODO: just use toml::Value -> json::Value DebugArgumentValue::String(v) => { DebugArgumentValue::String(v.replace(&pattern, ¶m)) } DebugArgumentValue::Array(arr) => DebugArgumentValue::Array( arr.iter().map(|v| v.replace(&pattern, ¶m)).collect(), ), + DebugArgumentValue::Boolean(_) => value, }; } - if let DebugArgumentValue::String(string) = value { - if let Ok(integer) = string.parse::<usize>() { - args.insert(k, to_value(integer).unwrap()); - } else { - args.insert(k, to_value(string).unwrap()); + match value { + DebugArgumentValue::String(string) => { + if let Ok(integer) = string.parse::<usize>() { + args.insert(k, to_value(integer).unwrap()); + } else { + args.insert(k, to_value(string).unwrap()); + } + } + DebugArgumentValue::Array(arr) => { + args.insert(k, to_value(arr).unwrap()); + } + DebugArgumentValue::Boolean(bool) => { + args.insert(k, to_value(bool).unwrap()); } - } else if let DebugArgumentValue::Array(arr) = value { - args.insert(k, to_value(arr).unwrap()); } } } let args = to_value(args).unwrap(); + // problem: this blocks for too long while we get back the startInTerminal REQ + + log::error!("pre start"); let result = match &template.request[..] { "launch" => block_on(debugger.launch(args)), "attach" => block_on(debugger.attach(args)), @@ -282,6 +293,7 @@ pub fn dap_start_impl( return; } }; + log::error!("post start"); if let Err(e) = result { let msg = format!("Failed {} target: {}", template.request, e); editor.set_error(msg); diff --git a/languages.toml b/languages.toml index 675bbbea..2b501651 100644 --- a/languages.toml +++ b/languages.toml @@ -24,6 +24,12 @@ completion = [ { name = "binary", completion = "filename" } ] args = { program = "{0}" } [[language.debugger.templates]] +name = "binary (terminal)" +request = "launch" +completion = [ { name = "binary", completion = "filename" } ] +args = { program = "{0}", runInTerminal = true } + +[[language.debugger.templates]] name = "attach" request = "attach" completion = [ "pid" ] |