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,
compositor::Compositor,
job::Callback,
ui::{FilePicker, Prompt, PromptEvent},
ui::{FilePicker, Picker, Prompt, PromptEvent},
};
use helix_core::{
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.editor.debug_config_completions = Some(
config
.templates
.iter()
.map(|t| t.completion.clone())
.collect(),
);
cx.push_layer(Box::new(Picker::new(
true,
config.templates.clone(),
|template| template.name.as_str().into(),
|editor, template, _action| {
let completions = template.completion.clone();
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) {

@ -902,29 +902,11 @@ impl EditorView {
cxt: &mut commands::Context,
event: KeyEvent,
) -> Option<KeymapResult> {
if let Some(picker) = cxt.editor.debug_config_picker.clone() {
match event {
KeyEvent {
code: KeyCode::Esc, ..
} => {}
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));
}
}
_ => return None,
}
cxt.editor.debug_config_picker = None;
if !cxt.editor.debug_config_completions.is_empty() {
let completions = std::mem::take(&mut cxt.editor.debug_config_completions);
// TODO name
let prompt = Self::debug_parameter_prompt(completions, "test".to_string(), Vec::new());
cxt.push_layer(Box::new(prompt));
return None;
}
@ -1429,26 +1411,6 @@ impl Component for EditorView {
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 let Some(ref mut info) = self.autoinfo {
info.render(area, surface, cx);

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

Loading…
Cancel
Save