From 94901b867796459f8dc3c1479eb896547877d769 Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Sat, 28 Aug 2021 19:11:19 +0300 Subject: Customized completion for template parameters --- helix-term/src/ui/editor.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'helix-term/src/ui') 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| { -- cgit v1.2.3-70-g09d2