diff options
author | Dmitry Sharshakov | 2021-08-28 16:11:19 +0000 |
---|---|---|
committer | Dmitry Sharshakov | 2021-08-28 16:11:19 +0000 |
commit | 94901b867796459f8dc3c1479eb896547877d769 (patch) | |
tree | 0c8cb625ab61360cf103a37ec32894254b1d161f /helix-term | |
parent | ef155e62ef411425c027a81c44cc76b5258ad48f (diff) |
Customized completion for template parameters
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 7 | ||||
-rw-r--r-- | helix-term/src/ui/editor.rs | 23 |
2 files changed, 27 insertions, 3 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index e5db1624..af6acb8c 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4630,6 +4630,13 @@ fn dap_launch(cx: &mut Context) { }; cx.editor.debug_config_picker = Some(config.templates.iter().map(|t| t.name.clone()).collect()); + cx.editor.debug_config_completions = Some( + config + .templates + .iter() + .map(|t| t.completion.clone()) + .collect(), + ); } fn dap_toggle_breakpoint(cx: &mut Context) { diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index fc7f32cc..09991919 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -25,6 +25,7 @@ use helix_view::{ keyboard::{KeyCode, KeyModifiers}, Document, Editor, Theme, View, }; +use log::warn; use std::borrow::Cow; use crossterm::event::{Event, MouseButton, MouseEvent, MouseEventKind}; @@ -729,14 +730,30 @@ impl EditorView { code: KeyCode::Char(char), .. } => { - let name = match picker.iter().find(|t| t.starts_with(char)) { - Some(n) => n.clone(), + let (i, name) = match picker.iter().position(|t| t.starts_with(char)) { + Some(pos) => (pos, picker.get(pos).unwrap().clone()), None => return None, }; + let completions = cxt.editor.debug_config_completions.clone().unwrap(); + let noop = |_input: &str| Vec::new(); + let completer = match completions.get(i) { + Some(Some(completion)) => { + match completion.get(0).and_then(|x| Some(x.as_str())) { + Some("filename") => super::completers::filename, + Some("directory") => super::completers::directory, + Some(complete) => { + warn!("Unknown debug config autocompleter: {}", complete); + noop + } + None => noop, + } + } + _ => noop, + }; let prompt = Prompt::new( "arg:".to_owned(), None, - super::completers::filename, + completer, move |cx: &mut crate::compositor::Context, input: &str, event: PromptEvent| { |