dap: Move template selection into a picker

It's time to move all these components out of ui/editor.rs
pull/574/head
Blaž Hrastnik 3 years ago
parent f2b709a3c3
commit 14a3502cf1

@ -3,7 +3,7 @@ use crate::{
commands, commands,
compositor::Compositor, compositor::Compositor,
job::Callback, job::Callback,
ui::{FilePicker, Prompt, PromptEvent}, ui::{FilePicker, Picker, Prompt, PromptEvent},
}; };
use helix_core::{ use helix_core::{
syntax::{DebugArgumentValue, DebugConfigCompletion}, syntax::{DebugArgumentValue, DebugConfigCompletion},
@ -319,14 +319,16 @@ pub fn dap_launch(cx: &mut Context) {
} }
}; };
cx.editor.debug_config_picker = Some(config.templates.iter().map(|t| t.name.clone()).collect()); cx.push_layer(Box::new(Picker::new(
cx.editor.debug_config_completions = Some( true,
config config.templates.clone(),
.templates |template| template.name.as_str().into(),
.iter() |editor, template, _action| {
.map(|t| t.completion.clone()) let completions = template.completion.clone();
.collect(), editor.debug_config_completions = completions;
); // TODO: need some way to manipulate the compositor to push a new prompt here
},
))); // TODO: wrap in popup with fixed size
} }
pub fn dap_toggle_breakpoint(cx: &mut Context) { pub fn dap_toggle_breakpoint(cx: &mut Context) {

@ -902,29 +902,11 @@ impl EditorView {
cxt: &mut commands::Context, cxt: &mut commands::Context,
event: KeyEvent, event: KeyEvent,
) -> Option<KeymapResult> { ) -> Option<KeymapResult> {
if let Some(picker) = cxt.editor.debug_config_picker.clone() { if !cxt.editor.debug_config_completions.is_empty() {
match event { let completions = std::mem::take(&mut cxt.editor.debug_config_completions);
KeyEvent { // TODO name
code: KeyCode::Esc, .. let prompt = Self::debug_parameter_prompt(completions, "test".to_string(), Vec::new());
} => {}
KeyEvent {
code: KeyCode::Char(char),
..
} => {
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 completion = completions.get(i).unwrap().clone();
if !completion.is_empty() {
let prompt = Self::debug_parameter_prompt(completion, name, Vec::new());
cxt.push_layer(Box::new(prompt)); cxt.push_layer(Box::new(prompt));
}
}
_ => return None,
}
cxt.editor.debug_config_picker = None;
return None; return None;
} }
@ -1429,26 +1411,6 @@ impl Component for EditorView {
info.render(area, surface, cx); info.render(area, surface, cx);
} }
if let Some(ref configs) = cx.editor.debug_config_picker {
let mut text = String::new();
let mut height = 0;
let mut max_len = 20;
for line in configs {
max_len = max_len.max(line.len() as u16 + 2);
height += 1;
text.push_str(&format!("{} {}\n", line.chars().next().unwrap(), line));
}
let mut info = Info {
height: 20.min(height + 1),
width: 70.min(max_len),
title: "Debug targets".to_owned(),
text: text + "Exit Esc",
};
info.render(area, surface, cx);
}
if cx.editor.config.auto_info { if cx.editor.config.auto_info {
if let Some(ref mut info) = self.autoinfo { if let Some(ref mut info) = self.autoinfo {
info.render(area, surface, cx); info.render(area, surface, cx);

@ -126,8 +126,7 @@ pub struct Editor {
pub debugger: Option<dap::Client>, pub debugger: Option<dap::Client>,
pub debugger_events: SelectAll<UnboundedReceiverStream<dap::Payload>>, pub debugger_events: SelectAll<UnboundedReceiverStream<dap::Payload>>,
pub breakpoints: HashMap<PathBuf, Vec<dap::SourceBreakpoint>>, pub breakpoints: HashMap<PathBuf, Vec<dap::SourceBreakpoint>>,
pub debug_config_picker: Option<Vec<String>>, pub debug_config_completions: Vec<DebugConfigCompletion>,
pub debug_config_completions: Option<Vec<Vec<DebugConfigCompletion>>>,
pub variables: Option<Vec<String>>, pub variables: Option<Vec<String>>,
pub variables_page: usize, pub variables_page: usize,
@ -175,8 +174,7 @@ impl Editor {
debugger: None, debugger: None,
debugger_events: SelectAll::new(), debugger_events: SelectAll::new(),
breakpoints: HashMap::new(), breakpoints: HashMap::new(),
debug_config_picker: None, debug_config_completions: Vec::new(),
debug_config_completions: None,
variables: None, variables: None,
variables_page: 0, variables_page: 0,
syn_loader: config_loader, syn_loader: config_loader,

Loading…
Cancel
Save