Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger template: allow missing or empty completion list #10332

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Debugger template: allow missing or empty completion list
It can be convenient to define project specific debugger templates, some of
which might not necessitate prompting the user to define completion.

This commit makes completion optional for debugger templates and starts the
dap immediately if undefined or empty.
  • Loading branch information
fengalin committed Apr 10, 2024
commit cacd15d957922ec737307b89c3d8fa882a9d31a3
1 change: 1 addition & 0 deletions helix-core/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ pub enum DebugArgumentValue {
pub struct DebugTemplate {
pub name: String,
pub request: String,
#[serde(default)]
pub completion: Vec<DebugConfigCompletion>,
pub args: HashMap<String, DebugArgumentValue>,
}
Expand Down
60 changes: 33 additions & 27 deletions helix-term/src/commands/dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ pub fn dap_start_impl(

let mut args: HashMap<&str, Value> = HashMap::new();

if let Some(params) = params {
for (k, t) in &template.args {
let mut value = t.clone();
for (k, t) in &template.args {
let mut value = t.clone();
if let Some(ref params) = params {
for (i, x) in params.iter().enumerate() {
let mut param = x.to_string();
if let Some(DebugConfigCompletion::Advanced(cfg)) = template.completion.get(i) {
Expand All @@ -198,22 +198,22 @@ pub fn dap_start_impl(
DebugArgumentValue::Boolean(_) => 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());
}
}
DebugArgumentValue::Array(arr) => {
args.insert(k, to_value(arr).unwrap());
}
DebugArgumentValue::Boolean(bool) => {
args.insert(k, to_value(bool).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());
}
}
}

Expand Down Expand Up @@ -272,17 +272,23 @@ pub fn dap_launch(cx: &mut Context) {
templates,
(),
|cx, template, _action| {
let completions = template.completion.clone();
let name = template.name.clone();
let callback = Box::pin(async move {
let call: Callback =
Callback::EditorCompositor(Box::new(move |_editor, compositor| {
let prompt = debug_parameter_prompt(completions, name, Vec::new());
compositor.push(Box::new(prompt));
}));
Ok(call)
});
cx.jobs.callback(callback);
if template.completion.is_empty() {
if let Err(err) = dap_start_impl(cx, Some(&template.name), None, None) {
cx.editor.set_error(err.to_string());
}
} else {
let completions = template.completion.clone();
let name = template.name.clone();
let callback = Box::pin(async move {
let call: Callback =
Callback::EditorCompositor(Box::new(move |_editor, compositor| {
let prompt = debug_parameter_prompt(completions, name, Vec::new());
compositor.push(Box::new(prompt));
}));
Ok(call)
});
cx.jobs.callback(callback);
}
},
))));
}
Expand Down
Loading