Customized completion for template parameters
This commit is contained in:
parent
ef155e62ef
commit
94901b8677
@ -7,6 +7,7 @@
|
||||
pub struct DebugTemplate {
|
||||
pub name: String,
|
||||
pub request: String,
|
||||
pub completion: Option<Vec<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_completions = Some(
|
||||
config
|
||||
.templates
|
||||
.iter()
|
||||
.map(|t| t.completion.clone())
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
|
||||
fn dap_toggle_breakpoint(cx: &mut Context) {
|
||||
|
@ -25,6 +25,7 @@
|
||||
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 @@ fn handle_keymap_event(
|
||||
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| {
|
||||
|
@ -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 @@ pub fn new(
|
||||
debugger: None,
|
||||
debugger_events: SelectAll::new(),
|
||||
debug_config_picker: None,
|
||||
debug_config_completions: None,
|
||||
variables: None,
|
||||
variables_page: 0,
|
||||
syn_loader: config_loader,
|
||||
|
@ -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]]
|
||||
|
Loading…
Reference in New Issue
Block a user