on master help sign in
Paginated variables
commit890b51b568bcbd8fdbe594f5fcda77d82c18288a authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSat 28 Aug 2021, 10:13 (5 years ago) parent3b87fce
3 files changed+64−4
helix-term/src/commands.rs+7−4 helix-term/src/ui/editor.rs+53 helix-view/src/editor.rs+4
helix-term/src/commands.rs+7−4
@@ -4768,7 +4768,7 @@ fn dap_variables(cx: &mut Context) {
47684768 return;
47694769 }
47704770 };
4771− let mut s = String::new();
4771+ let mut variables = Vec::new();
47724772
47734773 for scope in scopes.iter() {
47744774 let response = block_on(debugger.variables(scope.variables_reference));
@@ -4779,12 +4779,15 @@ fn dap_variables(cx: &mut Context) {
47794779 Some(data_type) => format!("{} ", data_type),
47804780 None => "".to_owned(),
47814781 };
4782− // s.push_str(&format!("{}{} = {}; ", prefix, var.name, var.value));
4783− s.push_str(&format!("{}{}; ", prefix, var.name,));
4782+ variables.push(format!("{}{} = {}\n", prefix, var.name, var.value));
47844783 }
47854784 }
47864785 }
4787− cx.editor.set_status(s);
4786+
4787+ if !variables.is_empty() {
4788+ cx.editor.variables = Some(variables);
4789+ cx.editor.variables_page = 0;
4790+ }
47884791 }
47894792}
47904793
helix-term/src/ui/editor.rs+53
@@ -711,6 +711,30 @@ impl EditorView {
711711 event: KeyEvent,
712712 ) -> Option<KeymapResult> {
713713 self.autoinfo = None;
714+
715+ if cxt.editor.variables.is_some() {
716+ match event {
717+ KeyEvent {
718+ code: KeyCode::Char('h'),
719+ ..
720+ } => {
721+ cxt.editor.variables_page = cxt.editor.variables_page.saturating_sub(1);
722+ }
723+ KeyEvent {
724+ code: KeyCode::Char('l'),
725+ ..
726+ } => {
727+ cxt.editor.variables_page = cxt.editor.variables_page.saturating_add(1);
728+ }
729+ KeyEvent {
730+ code: KeyCode::Esc, ..
731+ } => {
732+ cxt.editor.variables = None;
733+ }
734+ _ => {}
735+ }
736+ return None;
737+ }
714738 match self.keymaps.get_mut(&mode).unwrap().get(event) {
715739 KeymapResult::Matched(command) => command.execute(cxt),
716740 KeymapResult::Pending(node) => self.autoinfo = Some(node.into()),
@@ -1084,6 +1108,35 @@ impl Component for EditorView {
10841108 );
10851109 }
10861110
1111+ if let Some(ref vars) = cx.editor.variables {
1112+ let mut text = String::new();
1113+ let mut height = 0;
1114+ let mut max_len = 0;
1115+
1116+ let per_page = 15;
1117+ let num_vars = vars.len();
1118+ let start = (per_page * cx.editor.variables_page).min(num_vars);
1119+ let end = (start + per_page).min(num_vars);
1120+ for line in vars[start..end].to_vec() {
1121+ max_len = max_len.max(line.len() as u16);
1122+ height += 1;
1123+ text.push_str(&line);
1124+ }
1125+
1126+ if vars.len() > per_page {
1127+ text += "\nMove h, l";
1128+ height += 1;
1129+ }
1130+
1131+ let mut info = Info {
1132+ height: 20.min(height + 2),
1133+ width: 70.min(max_len),
1134+ title: format!("{} variables", num_vars),
1135+ text: text + "\nExit Esc",
1136+ };
1137+ info.render(area, surface, cx);
1138+ }
1139+
10871140 if let Some(ref mut info) = self.autoinfo {
10881141 info.render(area, surface, cx);
10891142 }
helix-view/src/editor.rs+4
@@ -76,6 +76,8 @@ pub struct Editor {
7676
7777 pub debugger: Option<helix_dap::Client>,
7878 pub debugger_events: SelectAll<UnboundedReceiverStream<helix_dap::Payload>>,
79+ pub variables: Option<Vec<String>>,
80+ pub variables_page: usize,
7981
8082 pub clipboard_provider: Box<dyn ClipboardProvider>,
8183
@@ -116,6 +118,8 @@ impl Editor {
116118 language_servers,
117119 debugger: None,
118120 debugger_events: SelectAll::new(),
121+ variables: None,
122+ variables_page: 0,
119123 syn_loader: config_loader,
120124 theme_loader: themes,
121125 registers: Registers::default(),