Customized completion for template parameters

pull/574/head
Dmitry Sharshakov 3 years ago
parent ef155e62ef
commit 94901b8677
No known key found for this signature in database
GPG Key ID: 471FD32E15FD8473

@ -7,6 +7,7 @@ use std::{collections::HashMap, path::PathBuf};
pub struct DebugTemplate { pub struct DebugTemplate {
pub name: String, pub name: String,
pub request: String, pub request: String,
pub completion: Option<Vec<String>>,
pub args: HashMap<String, String>, pub args: HashMap<String, String>,
} }

@ -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_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) { fn dap_toggle_breakpoint(cx: &mut Context) {

@ -25,6 +25,7 @@ use helix_view::{
keyboard::{KeyCode, KeyModifiers}, keyboard::{KeyCode, KeyModifiers},
Document, Editor, Theme, View, Document, Editor, Theme, View,
}; };
use log::warn;
use std::borrow::Cow; use std::borrow::Cow;
use crossterm::event::{Event, MouseButton, MouseEvent, MouseEventKind}; use crossterm::event::{Event, MouseButton, MouseEvent, MouseEventKind};
@ -729,14 +730,30 @@ impl EditorView {
code: KeyCode::Char(char), code: KeyCode::Char(char),
.. ..
} => { } => {
let name = match picker.iter().find(|t| t.starts_with(char)) { let (i, name) = match picker.iter().position(|t| t.starts_with(char)) {
Some(n) => n.clone(), Some(pos) => (pos, picker.get(pos).unwrap().clone()),
None => return None, 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( let prompt = Prompt::new(
"arg:".to_owned(), "arg:".to_owned(),
None, None,
super::completers::filename, completer,
move |cx: &mut crate::compositor::Context, move |cx: &mut crate::compositor::Context,
input: &str, input: &str,
event: PromptEvent| { event: PromptEvent| {

@ -77,6 +77,7 @@ pub struct Editor {
pub debugger: Option<helix_dap::Client>, pub debugger: Option<helix_dap::Client>,
pub debugger_events: SelectAll<UnboundedReceiverStream<helix_dap::Payload>>, pub debugger_events: SelectAll<UnboundedReceiverStream<helix_dap::Payload>>,
pub debug_config_picker: Option<Vec<String>>, pub debug_config_picker: Option<Vec<String>>,
pub debug_config_completions: Option<Vec<Option<Vec<String>>>>,
pub variables: Option<Vec<String>>, pub variables: Option<Vec<String>>,
pub variables_page: usize, pub variables_page: usize,
@ -120,6 +121,7 @@ impl Editor {
debugger: None, debugger: None,
debugger_events: SelectAll::new(), debugger_events: SelectAll::new(),
debug_config_picker: None, debug_config_picker: None,
debug_config_completions: None,
variables: None, variables: None,
variables_page: 0, variables_page: 0,
syn_loader: config_loader, syn_loader: config_loader,

@ -30,6 +30,7 @@ port-arg = "-p {}"
[[language.debugger.templates]] [[language.debugger.templates]]
name = "binary" name = "binary"
request = "launch" request = "launch"
completion = [ "filename" ]
args = { console = "internalConsole", program = "{0}" } args = { console = "internalConsole", program = "{0}" }
[[language.debugger.templates]] [[language.debugger.templates]]
@ -97,6 +98,7 @@ port-arg = "-p {}"
[[language.debugger.templates]] [[language.debugger.templates]]
name = "binary" name = "binary"
request = "launch" request = "launch"
completion = [ "filename" ]
args = { console = "internalConsole", program = "{0}" } args = { console = "internalConsole", program = "{0}" }
[[language.debugger.templates]] [[language.debugger.templates]]
@ -125,6 +127,7 @@ port-arg = "-p {}"
[[language.debugger.templates]] [[language.debugger.templates]]
name = "binary" name = "binary"
request = "launch" request = "launch"
completion = [ "filename" ]
args = { console = "internalConsole", program = "{0}" } args = { console = "internalConsole", program = "{0}" }
[[language.debugger.templates]] [[language.debugger.templates]]
@ -155,16 +158,19 @@ port-arg = "-l 127.0.0.1:{}"
[[language.debugger.templates]] [[language.debugger.templates]]
name = "source" name = "source"
request = "launch" request = "launch"
completion = [ "filename" ]
args = { mode = "debug", program = "{0}" } args = { mode = "debug", program = "{0}" }
[[language.debugger.templates]] [[language.debugger.templates]]
name = "binary" name = "binary"
request = "launch" request = "launch"
completion = [ "filename" ]
args = { mode = "exec", program = "{0}" } args = { mode = "exec", program = "{0}" }
[[language.debugger.templates]] [[language.debugger.templates]]
name = "test" name = "test"
request = "launch" request = "launch"
completion = [ "directory" ]
args = { mode = "test", program = "{0}" } args = { mode = "test", program = "{0}" }
[[language.debugger.templates]] [[language.debugger.templates]]

Loading…
Cancel
Save