on master help sign in
dap: Move template selection into a picker

It's time to move all these components out of ui/editor.rs

commit14a3502cf132b93b47b12cf14c685f0b694893c6 authorBlaž Hrastnik <blaz@mxxn.io> dateSun 17 Oct 2021, 15:14 (5 years ago) parentf2b709a
3 files changed+18−56
helix-term/src/commands/dap.rs+11−9 helix-term/src/ui/editor.rs+5−43 helix-view/src/editor.rs+2−4
helix-term/src/commands/dap.rs+11−9
@@ -3,7 +3,7 @@ use crate::{
33 commands,
44 compositor::Compositor,
55 job::Callback,
6− ui::{FilePicker, Prompt, PromptEvent},
6+ ui::{FilePicker, Picker, Prompt, PromptEvent},
77};
88use helix_core::{
99 syntax::{DebugArgumentValue, DebugConfigCompletion},
@@ -319,14 +319,16 @@ pub fn dap_launch(cx: &mut Context) {
319319 }
320320 };
321321
322− cx.editor.debug_config_picker = Some(config.templates.iter().map(|t| t.name.clone()).collect());
323− cx.editor.debug_config_completions = Some(
324− config
325− .templates
326− .iter()
327− .map(|t| t.completion.clone())
328− .collect(),
329− );
322+ cx.push_layer(Box::new(Picker::new(
323+ true,
324+ config.templates.clone(),
325+ |template| template.name.as_str().into(),
326+ |editor, template, _action| {
327+ let completions = template.completion.clone();
328+ editor.debug_config_completions = completions;
329+ // TODO: need some way to manipulate the compositor to push a new prompt here
330+ },
331+ ))); // TODO: wrap in popup with fixed size
330332}
331333
332334pub fn dap_toggle_breakpoint(cx: &mut Context) {
helix-term/src/ui/editor.rs+5−43
@@ -902,29 +902,11 @@ impl EditorView {
902902 cxt: &mut commands::Context,
903903 event: KeyEvent,
904904 ) -> Option<KeymapResult> {
905− if let Some(picker) = cxt.editor.debug_config_picker.clone() {
906− match event {
907− KeyEvent {
908− code: KeyCode::Esc, ..
909− } => {}
910− KeyEvent {
911− code: KeyCode::Char(char),
912− ..
913− } => {
914− let (i, name) = match picker.iter().position(|t| t.starts_with(char)) {
915− Some(pos) => (pos, picker.get(pos).unwrap().clone()),
916− None => return None,
917− };
918− let completions = cxt.editor.debug_config_completions.clone().unwrap();
919− let completion = completions.get(i).unwrap().clone();
920− if !completion.is_empty() {
921− let prompt = Self::debug_parameter_prompt(completion, name, Vec::new());
922− cxt.push_layer(Box::new(prompt));
923− }
924− }
925− _ => return None,
926− }
927− cxt.editor.debug_config_picker = None;
905+ if !cxt.editor.debug_config_completions.is_empty() {
906+ let completions = std::mem::take(&mut cxt.editor.debug_config_completions);
907+ // TODO name
908+ let prompt = Self::debug_parameter_prompt(completions, "test".to_string(), Vec::new());
909+ cxt.push_layer(Box::new(prompt));
928910 return None;
929911 }
930912
@@ -1429,26 +1411,6 @@ impl Component for EditorView {
14291411 info.render(area, surface, cx);
14301412 }
14311413
1432− if let Some(ref configs) = cx.editor.debug_config_picker {
1433− let mut text = String::new();
1434− let mut height = 0;
1435− let mut max_len = 20;
1436−
1437− for line in configs {
1438− max_len = max_len.max(line.len() as u16 + 2);
1439− height += 1;
1440− text.push_str(&format!("{} {}\n", line.chars().next().unwrap(), line));
1441− }
1442−
1443− let mut info = Info {
1444− height: 20.min(height + 1),
1445− width: 70.min(max_len),
1446− title: "Debug targets".to_owned(),
1447− text: text + "Exit Esc",
1448− };
1449− info.render(area, surface, cx);
1450− }
1451−
14521414 if cx.editor.config.auto_info {
14531415 if let Some(ref mut info) = self.autoinfo {
14541416 info.render(area, surface, cx);
helix-view/src/editor.rs+2−4
@@ -126,8 +126,7 @@ pub struct Editor {
126126 pub debugger: Option<dap::Client>,
127127 pub debugger_events: SelectAll<UnboundedReceiverStream<dap::Payload>>,
128128 pub breakpoints: HashMap<PathBuf, Vec<dap::SourceBreakpoint>>,
129− pub debug_config_picker: Option<Vec<String>>,
130− pub debug_config_completions: Option<Vec<Vec<DebugConfigCompletion>>>,
129+ pub debug_config_completions: Vec<DebugConfigCompletion>,
131130 pub variables: Option<Vec<String>>,
132131 pub variables_page: usize,
133132
@@ -175,8 +174,7 @@ impl Editor {
175174 debugger: None,
176175 debugger_events: SelectAll::new(),
177176 breakpoints: HashMap::new(),
178− debug_config_picker: None,
179− debug_config_completions: None,
177+ debug_config_completions: Vec::new(),
180178 variables: None,
181179 variables_page: 0,
182180 syn_loader: config_loader,