on master help sign in
dap: Extract out variable rendering
64bb1f7Blaž Hrastnik
helix-term/src/commands/dap.rs+5−6
@@ -3,7 +3,7 @@ use crate::{
3 commands,
3 commands,
4 compositor::Compositor,
4 compositor::Compositor,
5 job::Callback,
5 job::Callback,
6− ui::{FilePicker, Picker, Prompt, PromptEvent},
6+ ui::{FilePicker, Picker, Popup, Prompt, PromptEvent, Text},
7};
7};
8use helix_core::{
8use helix_core::{
9 syntax::{DebugArgumentValue, DebugConfigCompletion},
9 syntax::{DebugArgumentValue, DebugConfigCompletion},
@@ -518,15 +518,14 @@ pub fn dap_variables(cx: &mut Context) {
518 Some(data_type) => format!("{} ", data_type),
518 Some(data_type) => format!("{} ", data_type),
519 None => "".to_owned(),
519 None => "".to_owned(),
520 };
520 };
521− variables.push(format!("{}{} = {}\n", prefix, var.name, var.value));
521+ variables.push(format!("{}{} = {}", prefix, var.name, var.value));
522 }
522 }
523 }
523 }
524 }
524 }
525
525
526− if !variables.is_empty() {
526+ let contents = Text::new(variables.join("\n"));
527− cx.editor.variables = Some(variables);
527+ let popup = Popup::new(contents);
528− cx.editor.variables_page = 0;
528+ cx.push_layer(Box::new(popup));
529− }
530}
529}
531
530
532pub fn dap_terminate(cx: &mut Context) {
531pub fn dap_terminate(cx: &mut Context) {
helix-term/src/ui/editor.rs+9−55
@@ -906,30 +906,6 @@ impl EditorView {
906 return None;
906 return None;
907 }
907 }
908
908
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−
933 let key_result = self.keymaps.get_mut(&mode).unwrap().get(event);
909 let key_result = self.keymaps.get_mut(&mode).unwrap().get(event);
934 self.autoinfo = key_result.sticky.map(|node| node.infobox());
910 self.autoinfo = key_result.sticky.map(|node| node.infobox());
935
911
@@ -1081,7 +1057,10 @@ impl EditorView {
1081 if let Some((line, _, view_id)) = result {
1057 if let Some((line, _, view_id)) = result {
1082 editor.tree.focus = view_id;
1058 editor.tree.focus = view_id;
1083
1059
1060+ let doc = editor
1061+ .documents
1084− let doc = editor.documents.get_mut(&editor.tree.get(view_id).doc).unwrap();
1062+ .get_mut(&editor.tree.get(view_id).doc)
1063+ .unwrap();
1085 if let Ok(pos) = doc.text().try_line_to_char(line) {
1064 if let Ok(pos) = doc.text().try_line_to_char(line) {
1086 doc.set_selection(view_id, Selection::point(pos));
1065 doc.set_selection(view_id, Selection::point(pos));
1087 commands::dap_toggle_breakpoint(cxt);
1066 commands::dap_toggle_breakpoint(cxt);
@@ -1180,7 +1159,11 @@ impl EditorView {
1180 if let Some((line, _, view_id)) = result {
1159 if let Some((line, _, view_id)) = result {
1181 cxt.editor.tree.focus = view_id;
1160 cxt.editor.tree.focus = view_id;
1182
1161
1162+ let doc = cxt
1163+ .editor
1164+ .documents
1183− let doc = cxt.editor.documents.get_mut(&cxt.editor.tree.get(view_id).doc).unwrap();
1165+ .get_mut(&cxt.editor.tree.get(view_id).doc)
1166+ .unwrap();
1184 if let Ok(pos) = doc.text().try_line_to_char(line) {
1167 if let Ok(pos) = doc.text().try_line_to_char(line) {
1185 doc.set_selection(view_id, Selection::point(pos));
1168 doc.set_selection(view_id, Selection::point(pos));
1186 if modifiers == crossterm::event::KeyModifiers::ALT {
1169 if modifiers == crossterm::event::KeyModifiers::ALT {
@@ -1378,35 +1361,6 @@ impl Component for EditorView {
1378 );
1361 );
1379 }
1362 }
1380
1363
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−
1410 if cx.editor.config.auto_info {
1364 if cx.editor.config.auto_info {
1411 if let Some(ref mut info) = self.autoinfo {
1365 if let Some(ref mut info) = self.autoinfo {
1412 info.render(area, surface, cx);
1366 info.render(area, surface, cx);
helix-view/src/editor.rs+1−5
@@ -11,8 +11,8 @@ use futures_util::stream::select_all::SelectAll;
11use tokio_stream::wrappers::UnboundedReceiverStream;
11use tokio_stream::wrappers::UnboundedReceiverStream;
12
12
13use std::{
13use std::{
14− collections::HashMap,
15 collections::BTreeMap,
14 collections::BTreeMap,
15+ collections::HashMap,
16 path::{Path, PathBuf},
16 path::{Path, PathBuf},
17 pin::Pin,
17 pin::Pin,
18 sync::Arc,
18 sync::Arc,
@@ -127,8 +127,6 @@ pub struct Editor {
127 pub debugger_events: SelectAll<UnboundedReceiverStream<dap::Payload>>,
127 pub debugger_events: SelectAll<UnboundedReceiverStream<dap::Payload>>,
128 pub breakpoints: HashMap<PathBuf, Vec<dap::SourceBreakpoint>>,
128 pub breakpoints: HashMap<PathBuf, Vec<dap::SourceBreakpoint>>,
129 pub debug_config_completions: Vec<DebugConfigCompletion>,
129 pub debug_config_completions: Vec<DebugConfigCompletion>,
130− pub variables: Option<Vec<String>>,
131− pub variables_page: usize,
132
130
133 pub clipboard_provider: Box<dyn ClipboardProvider>,
131 pub clipboard_provider: Box<dyn ClipboardProvider>,
134
132
@@ -175,8 +173,6 @@ impl Editor {
175 debugger_events: SelectAll::new(),
173 debugger_events: SelectAll::new(),
176 breakpoints: HashMap::new(),
174 breakpoints: HashMap::new(),
177 debug_config_completions: Vec::new(),
175 debug_config_completions: Vec::new(),
178− variables: None,
179− variables_page: 0,
180 syn_loader: config_loader,
176 syn_loader: config_loader,
181 theme_loader: themes,
177 theme_loader: themes,
182 registers: Registers::default(),
178 registers: Registers::default(),