on master help sign in
dap: Extract out variable rendering

Will improve on the UI later

commit64bb1f75639136868d762b79daa9cc659bf601d0 authorBlaž Hrastnik <blaz@mxxn.io> dateSun 7 Nov 2021, 17:55 (5 years ago) parente2a23ac
3 files changed+15−66
helix-term/src/commands/dap.rs+5−6 helix-term/src/ui/editor.rs+9−55 helix-view/src/editor.rs+1−5
helix-term/src/commands/dap.rs+5−6
@@ -3,7 +3,7 @@ use crate::{
33 commands,
44 compositor::Compositor,
55 job::Callback,
6− ui::{FilePicker, Picker, Prompt, PromptEvent},
6+ ui::{FilePicker, Picker, Popup, Prompt, PromptEvent, Text},
77};
88use helix_core::{
99 syntax::{DebugArgumentValue, DebugConfigCompletion},
@@ -518,15 +518,14 @@ pub fn dap_variables(cx: &mut Context) {
518518 Some(data_type) => format!("{} ", data_type),
519519 None => "".to_owned(),
520520 };
521− variables.push(format!("{}{} = {}\n", prefix, var.name, var.value));
521+ variables.push(format!("{}{} = {}", prefix, var.name, var.value));
522522 }
523523 }
524524 }
525525
526− if !variables.is_empty() {
527− cx.editor.variables = Some(variables);
528− cx.editor.variables_page = 0;
529− }
526+ let contents = Text::new(variables.join("\n"));
527+ let popup = Popup::new(contents);
528+ cx.push_layer(Box::new(popup));
530529}
531530
532531pub fn dap_terminate(cx: &mut Context) {
helix-term/src/ui/editor.rs+9−55
@@ -906,30 +906,6 @@ impl EditorView {
906906 return None;
907907 }
908908
909− if cxt.editor.variables.is_some() {
910− match event {
911− KeyEvent {
912− code: KeyCode::Char('h'),
913− ..
914− } => {
915− cxt.editor.variables_page = cxt.editor.variables_page.saturating_sub(1);
916− }
917− KeyEvent {
918− code: KeyCode::Char('l'),
919− ..
920− } => {
921− cxt.editor.variables_page = cxt.editor.variables_page.saturating_add(1);
922− }
923− KeyEvent {
924− code: KeyCode::Esc, ..
925− } => {
926− cxt.editor.variables = None;
927− }
928− _ => {}
929− }
930− return None;
931− }
932−
933909 let key_result = self.keymaps.get_mut(&mode).unwrap().get(event);
934910 self.autoinfo = key_result.sticky.map(|node| node.infobox());
935911
@@ -1081,7 +1057,10 @@ impl EditorView {
10811057 if let Some((line, _, view_id)) = result {
10821058 editor.tree.focus = view_id;
10831059
1084− let doc = editor.documents.get_mut(&editor.tree.get(view_id).doc).unwrap();
1060+ let doc = editor
1061+ .documents
1062+ .get_mut(&editor.tree.get(view_id).doc)
1063+ .unwrap();
10851064 if let Ok(pos) = doc.text().try_line_to_char(line) {
10861065 doc.set_selection(view_id, Selection::point(pos));
10871066 commands::dap_toggle_breakpoint(cxt);
@@ -1180,7 +1159,11 @@ impl EditorView {
11801159 if let Some((line, _, view_id)) = result {
11811160 cxt.editor.tree.focus = view_id;
11821161
1183− let doc = cxt.editor.documents.get_mut(&cxt.editor.tree.get(view_id).doc).unwrap();
1162+ let doc = cxt
1163+ .editor
1164+ .documents
1165+ .get_mut(&cxt.editor.tree.get(view_id).doc)
1166+ .unwrap();
11841167 if let Ok(pos) = doc.text().try_line_to_char(line) {
11851168 doc.set_selection(view_id, Selection::point(pos));
11861169 if modifiers == crossterm::event::KeyModifiers::ALT {
@@ -1378,35 +1361,6 @@ impl Component for EditorView {
13781361 );
13791362 }
13801363
1381− if let Some(ref vars) = cx.editor.variables {
1382− let mut text = String::new();
1383− let mut height = 0;
1384− let mut max_len = 20;
1385−
1386− let per_page = 15;
1387− let num_vars = vars.len();
1388− let start = (per_page * cx.editor.variables_page).min(num_vars);
1389− let end = (start + per_page).min(num_vars);
1390− for line in vars[start..end].to_vec() {
1391− max_len = max_len.max(line.len() as u16);
1392− height += 1;
1393− text.push_str(&line);
1394− }
1395−
1396− if vars.len() > per_page {
1397− text += "\nMove h, l";
1398− height += 1;
1399− }
1400−
1401− let mut info = Info {
1402− height: 20.min(height + 2),
1403− width: 70.min(max_len),
1404− title: format!("{} variables", num_vars),
1405− text: text + "\nExit Esc",
1406− };
1407− info.render(area, surface, cx);
1408− }
1409−
14101364 if cx.editor.config.auto_info {
14111365 if let Some(ref mut info) = self.autoinfo {
14121366 info.render(area, surface, cx);
helix-view/src/editor.rs+1−5
@@ -11,8 +11,8 @@ use futures_util::stream::select_all::SelectAll;
1111use tokio_stream::wrappers::UnboundedReceiverStream;
1212
1313use std::{
14− collections::HashMap,
1514 collections::BTreeMap,
15+ collections::HashMap,
1616 path::{Path, PathBuf},
1717 pin::Pin,
1818 sync::Arc,
@@ -127,8 +127,6 @@ pub struct Editor {
127127 pub debugger_events: SelectAll<UnboundedReceiverStream<dap::Payload>>,
128128 pub breakpoints: HashMap<PathBuf, Vec<dap::SourceBreakpoint>>,
129129 pub debug_config_completions: Vec<DebugConfigCompletion>,
130− pub variables: Option<Vec<String>>,
131− pub variables_page: usize,
132130
133131 pub clipboard_provider: Box<dyn ClipboardProvider>,
134132
@@ -175,8 +173,6 @@ impl Editor {
175173 debugger_events: SelectAll::new(),
176174 breakpoints: HashMap::new(),
177175 debug_config_completions: Vec::new(),
178− variables: None,
179− variables_page: 0,
180176 syn_loader: config_loader,
181177 theme_loader: themes,
182178 registers: Registers::default(),