aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorDmitry Sharshakov2021-08-28 07:13:19 +0000
committerDmitry Sharshakov2021-08-28 07:13:19 +0000
commit890b51b568bcbd8fdbe594f5fcda77d82c18288a (patch)
tree12db1694a6e1c346856ef6eb45605fc8c3923889 /helix-term/src
parent3b87fce0cedc1cd2b4d5d41ddd76daa0dc3f7f2e (diff)
Paginated variables
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs11
-rw-r--r--helix-term/src/ui/editor.rs53
2 files changed, 60 insertions, 4 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 9cf8bb5c..62200d76 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -4768,7 +4768,7 @@ fn dap_variables(cx: &mut Context) {
return;
}
};
- let mut s = String::new();
+ let mut variables = Vec::new();
for scope in scopes.iter() {
let response = block_on(debugger.variables(scope.variables_reference));
@@ -4779,12 +4779,15 @@ fn dap_variables(cx: &mut Context) {
Some(data_type) => format!("{} ", data_type),
None => "".to_owned(),
};
- // s.push_str(&format!("{}{} = {}; ", prefix, var.name, var.value));
- s.push_str(&format!("{}{}; ", prefix, var.name,));
+ variables.push(format!("{}{} = {}\n", prefix, var.name, var.value));
}
}
}
- cx.editor.set_status(s);
+
+ if !variables.is_empty() {
+ cx.editor.variables = Some(variables);
+ cx.editor.variables_page = 0;
+ }
}
}
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index 92a631ed..4843b9ed 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -711,6 +711,30 @@ impl EditorView {
event: KeyEvent,
) -> Option<KeymapResult> {
self.autoinfo = None;
+
+ if cxt.editor.variables.is_some() {
+ match event {
+ KeyEvent {
+ code: KeyCode::Char('h'),
+ ..
+ } => {
+ cxt.editor.variables_page = cxt.editor.variables_page.saturating_sub(1);
+ }
+ KeyEvent {
+ code: KeyCode::Char('l'),
+ ..
+ } => {
+ cxt.editor.variables_page = cxt.editor.variables_page.saturating_add(1);
+ }
+ KeyEvent {
+ code: KeyCode::Esc, ..
+ } => {
+ cxt.editor.variables = None;
+ }
+ _ => {}
+ }
+ return None;
+ }
match self.keymaps.get_mut(&mode).unwrap().get(event) {
KeymapResult::Matched(command) => command.execute(cxt),
KeymapResult::Pending(node) => self.autoinfo = Some(node.into()),
@@ -1084,6 +1108,35 @@ impl Component for EditorView {
);
}
+ if let Some(ref vars) = cx.editor.variables {
+ let mut text = String::new();
+ let mut height = 0;
+ let mut max_len = 0;
+
+ let per_page = 15;
+ let num_vars = vars.len();
+ let start = (per_page * cx.editor.variables_page).min(num_vars);
+ let end = (start + per_page).min(num_vars);
+ for line in vars[start..end].to_vec() {
+ max_len = max_len.max(line.len() as u16);
+ height += 1;
+ text.push_str(&line);
+ }
+
+ if vars.len() > per_page {
+ text += "\nMove h, l";
+ height += 1;
+ }
+
+ let mut info = Info {
+ height: 20.min(height + 2),
+ width: 70.min(max_len),
+ title: format!("{} variables", num_vars),
+ text: text + "\nExit Esc",
+ };
+ info.render(area, surface, cx);
+ }
+
if let Some(ref mut info) = self.autoinfo {
info.render(area, surface, cx);
}