dap: Start working on runInTerminal support

pull/574/head
Blaž Hrastnik 3 years ago
parent 0d73a4d23a
commit 2dbf966293

@ -114,6 +114,7 @@ pub enum DebugConfigCompletion {
pub enum DebugArgumentValue {
String(String),
Array(Vec<String>),
Boolean(bool),
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]

@ -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),

@ -321,13 +321,14 @@ 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};
match payload {
Payload::Event(ev) => {
let debugger = match self.editor.debugger.as_mut() {
Some(debugger) => debugger,
None => return,
};
match payload {
Payload::Event(ev) => match ev {
match ev {
Event::Stopped(events::Stopped {
thread_id,
description,
@ -386,7 +387,8 @@ impl Application {
Event::Thread(_) => {
// TODO: update thread_states, make threads request
}
Event::Breakpoint(events::Breakpoint { reason, breakpoint }) => match &reason[..] {
Event::Breakpoint(events::Breakpoint { reason, breakpoint }) => {
match &reason[..] {
"new" => {
if let Some(source) = breakpoint.source {
self.editor
@ -405,18 +407,21 @@ impl Application {
}
"changed" => {
for breakpoints in self.editor.breakpoints.values_mut() {
if let Some(i) = breakpoints.iter().position(|b| b.id == breakpoint.id)
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].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)
if let Some(i) =
breakpoints.iter().position(|b| b.id == breakpoint.id)
{
breakpoints.remove(i);
}
@ -425,7 +430,8 @@ impl Application {
reason => {
warn!("Unknown breakpoint event: {}", reason);
}
},
}
}
Event::Output(events::Output {
category, output, ..
}) => {
@ -459,9 +465,10 @@ impl Application {
log::warn!("Unhandled event {:?}", ev);
return; // return early to skip render
}
},
}
}
Payload::Response(_) => unreachable!(),
Payload::Request(_) => todo!(),
Payload::Request(request) => unimplemented!("{:?}", request),
}
self.render();
}

@ -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, &param))
}
DebugArgumentValue::Array(arr) => DebugArgumentValue::Array(
arr.iter().map(|v| v.replace(&pattern, &param)).collect(),
),
DebugArgumentValue::Boolean(_) => value,
};
}
if let DebugArgumentValue::String(string) = value {
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());
}
} else if let DebugArgumentValue::Array(arr) = value {
}
DebugArgumentValue::Array(arr) => {
args.insert(k, to_value(arr).unwrap());
}
DebugArgumentValue::Boolean(bool) => {
args.insert(k, to_value(bool).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);

@ -23,6 +23,12 @@ request = "launch"
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"

Loading…
Cancel
Save