diff options
-rw-r--r-- | helix-dap/src/types.rs | 1 | ||||
-rw-r--r-- | helix-term/src/commands.rs | 7 | ||||
-rw-r--r-- | helix-term/src/ui/editor.rs | 23 | ||||
-rw-r--r-- | helix-view/src/editor.rs | 2 | ||||
-rw-r--r-- | languages.toml | 6 |
5 files changed, 36 insertions, 3 deletions
diff --git a/helix-dap/src/types.rs b/helix-dap/src/types.rs index 03f22e4d..d31b8023 100644 --- a/helix-dap/src/types.rs +++ b/helix-dap/src/types.rs @@ -7,6 +7,7 @@ use std::{collections::HashMap, path::PathBuf}; pub struct DebugTemplate { pub name: String, pub request: String, + pub completion: Option<Vec<String>>, pub args: HashMap<String, String>, } 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| { diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index c1b9cf1a..9644ba57 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -77,6 +77,7 @@ pub struct Editor { pub debugger: Option<helix_dap::Client>, pub debugger_events: SelectAll<UnboundedReceiverStream<helix_dap::Payload>>, pub debug_config_picker: Option<Vec<String>>, + pub debug_config_completions: Option<Vec<Option<Vec<String>>>>, pub variables: Option<Vec<String>>, pub variables_page: usize, @@ -120,6 +121,7 @@ impl Editor { debugger: None, debugger_events: SelectAll::new(), debug_config_picker: None, + debug_config_completions: None, variables: None, variables_page: 0, syn_loader: config_loader, diff --git a/languages.toml b/languages.toml index f4badb6e..ef263293 100644 --- a/languages.toml +++ b/languages.toml @@ -30,6 +30,7 @@ port-arg = "-p {}" [[language.debugger.templates]] name = "binary" request = "launch" +completion = [ "filename" ] args = { console = "internalConsole", program = "{0}" } [[language.debugger.templates]] @@ -97,6 +98,7 @@ port-arg = "-p {}" [[language.debugger.templates]] name = "binary" request = "launch" +completion = [ "filename" ] args = { console = "internalConsole", program = "{0}" } [[language.debugger.templates]] @@ -125,6 +127,7 @@ port-arg = "-p {}" [[language.debugger.templates]] name = "binary" request = "launch" +completion = [ "filename" ] args = { console = "internalConsole", program = "{0}" } [[language.debugger.templates]] @@ -155,16 +158,19 @@ port-arg = "-l 127.0.0.1:{}" [[language.debugger.templates]] name = "source" request = "launch" +completion = [ "filename" ] args = { mode = "debug", program = "{0}" } [[language.debugger.templates]] name = "binary" request = "launch" +completion = [ "filename" ] args = { mode = "exec", program = "{0}" } [[language.debugger.templates]] name = "test" request = "launch" +completion = [ "directory" ] args = { mode = "test", program = "{0}" } [[language.debugger.templates]] |