Paginated variables

imgbot
Dmitry Sharshakov 3 years ago
parent 3b87fce0ce
commit 890b51b568
No known key found for this signature in database
GPG Key ID: 471FD32E15FD8473

@ -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;
}
}
}

@ -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);
}

@ -76,6 +76,8 @@ pub struct Editor {
pub debugger: Option<helix_dap::Client>,
pub debugger_events: SelectAll<UnboundedReceiverStream<helix_dap::Payload>>,
pub variables: Option<Vec<String>>,
pub variables_page: usize,
pub clipboard_provider: Box<dyn ClipboardProvider>,
@ -116,6 +118,8 @@ impl Editor {
language_servers,
debugger: None,
debugger_events: SelectAll::new(),
variables: None,
variables_page: 0,
syn_loader: config_loader,
theme_loader: themes,
registers: Registers::default(),

Loading…
Cancel
Save