on master help sign in
wip: refactor parameters in UI start
2d42766Dmitry Sharshakov
helix-dap/src/types.rs+1−1
@@ -7,7 +7,7 @@ use std::{collections::HashMap, path::PathBuf};
7pub struct DebugTemplate {
7pub struct DebugTemplate {
8 pub name: String,
8 pub name: String,
9 pub request: String,
9 pub request: String,
10− pub completion: Option<Vec<String>>,
10+ pub completion: Vec<String>,
11 pub args: HashMap<String, String>,
11 pub args: HashMap<String, String>,
12}
12}
13
13
helix-term/src/ui/editor.rs+52−32
@@ -709,6 +709,54 @@ impl EditorView {
709 );
709 );
710 }
710 }
711
711
712+ fn request_parameter(
713+ completions: Vec<String>,
714+ config_name: String,
715+ cxt: &mut commands::Context,
716+ mut params: Vec<String>,
717+ ) {
718+ let noop = |_input: &str| Vec::new();
719+ let completer = match completions.get(0).map(|x| x.as_str()) {
720+ Some("filename") => super::completers::filename,
721+ Some("directory") => super::completers::directory,
722+ Some(complete) => {
723+ warn!("Unknown debug config autocompleter: {}", complete);
724+ noop
725+ }
726+ None => noop,
727+ };
728+ let prompt = Prompt::new(
729+ "arg: ".to_owned(),
730+ None,
731+ completer,
732+ move |cx: &mut crate::compositor::Context, input: &str, event: PromptEvent| {
733+ if event != PromptEvent::Validate {
734+ return;
735+ }
736+
737+ params.push(input.to_owned());
738+
739+ if params.len() < completions.len() {
740+ todo!();
741+ // Self::request_parameter(
742+ // completions.clone(),
743+ // config_name.clone(),
744+ // cxt,
745+ // params.clone(),
746+ // );
747+ } else {
748+ commands::dap_start_impl(
749+ cx.editor,
750+ Some(&config_name),
751+ None,
752+ Some(params.iter().map(|x| x.as_str()).collect()),
753+ );
754+ }
755+ },
756+ );
757+ cxt.push_layer(Box::new(prompt));
758+ }
759+
712 /// Handle events by looking them up in `self.keymaps`. Returns None
760 /// Handle events by looking them up in `self.keymaps`. Returns None
713 /// if event was handled (a command was executed or a subkeymap was
761 /// if event was handled (a command was executed or a subkeymap was
714 /// activated). Only KeymapResult::{NotFound, Cancelled} is returned
762 /// activated). Only KeymapResult::{NotFound, Cancelled} is returned
@@ -735,38 +783,10 @@ impl EditorView {
735 None => return None,
783 None => return None,
736 };
784 };
737 let completions = cxt.editor.debug_config_completions.clone().unwrap();
785 let completions = cxt.editor.debug_config_completions.clone().unwrap();
738− let noop = |_input: &str| Vec::new();
739− let completer = match completions.get(i) {
786+ let completion = completions.get(i).unwrap().clone();
740− Some(Some(completion)) => match completion.get(0).map(|x| x.as_str()) {
787+ if !completion.is_empty() {
741− Some("filename") => super::completers::filename,
788+ Self::request_parameter(completion, name, cxt, Vec::new());
742− Some("directory") => super::completers::directory,
789+ }
743− Some(complete) => {
744− warn!("Unknown debug config autocompleter: {}", complete);
745− noop
746− }
747− None => noop,
748− },
749− _ => noop,
750− };
751− let prompt = Prompt::new(
752− "arg:".to_owned(),
753− None,
754− completer,
755− move |cx: &mut crate::compositor::Context,
756− input: &str,
757− event: PromptEvent| {
758− if event != PromptEvent::Validate {
759− return;
760− }
761− commands::dap_start_impl(
762− cx.editor,
763− Some(&name),
764− None,
765− Some(vec![input]),
766− );
767− },
768− );
769− cxt.push_layer(Box::new(prompt));
770 }
790 }
771 _ => return None,
791 _ => return None,
772 }
792 }
helix-view/src/editor.rs+1−1
@@ -77,7 +77,7 @@ pub struct Editor {
77 pub debugger: Option<helix_dap::Client>,
77 pub debugger: Option<helix_dap::Client>,
78 pub debugger_events: SelectAll<UnboundedReceiverStream<helix_dap::Payload>>,
78 pub debugger_events: SelectAll<UnboundedReceiverStream<helix_dap::Payload>>,
79 pub debug_config_picker: Option<Vec<String>>,
79 pub debug_config_picker: Option<Vec<String>>,
80− pub debug_config_completions: Option<Vec<Option<Vec<String>>>>,
80+ pub debug_config_completions: Option<Vec<Vec<String>>>,
81 pub variables: Option<Vec<String>>,
81 pub variables: Option<Vec<String>>,
82 pub variables_page: usize,
82 pub variables_page: usize,
83
83
languages.toml+4
@@ -36,6 +36,7 @@ args = { console = "internalConsole", program = "{0}" }
36[[language.debugger.templates]]
36[[language.debugger.templates]]
37name = "attach"
37name = "attach"
38request = "attach"
38request = "attach"
39+completion = [ "none" ]
39args = { console = "internalConsole", pid = "{0}" }
40args = { console = "internalConsole", pid = "{0}" }
40
41
41[[language]]
42[[language]]
@@ -104,6 +105,7 @@ args = { console = "internalConsole", program = "{0}" }
104[[language.debugger.templates]]
105[[language.debugger.templates]]
105name = "attach"
106name = "attach"
106request = "attach"
107request = "attach"
108+completion = [ "none" ]
107args = { console = "internalConsole", pid = "{0}" }
109args = { console = "internalConsole", pid = "{0}" }
108
110
109[[language]]
111[[language]]
@@ -133,6 +135,7 @@ args = { console = "internalConsole", program = "{0}" }
133[[language.debugger.templates]]
135[[language.debugger.templates]]
134name = "attach"
136name = "attach"
135request = "attach"
137request = "attach"
138+completion = [ "none" ]
136args = { console = "internalConsole", pid = "{0}" }
139args = { console = "internalConsole", pid = "{0}" }
137
140
138[[language]]
141[[language]]
@@ -176,6 +179,7 @@ args = { mode = "test", program = "{0}" }
176[[language.debugger.templates]]
179[[language.debugger.templates]]
177name = "attach"
180name = "attach"
178request = "attach"
181request = "attach"
182+completion = [ "none" ]
179args = { mode = "local", processId = "{0}" }
183args = { mode = "local", processId = "{0}" }
180
184
181[[language]]
185[[language]]