on master help sign in
Simplify variables display
commit838f69929db3d9d1e30fa52913a730f2e64b0681 authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSun 22 Aug 2021, 12:49 (5 years ago) parent060a422
2 files changed+16−60
helix-term/src/commands.rs+15−59 helix-term/src/keymap.rs+1−1
helix-term/src/commands.rs+15−59
@@ -311,7 +311,7 @@ impl Command {
311311 dap_in, "Step in",
312312 dap_out, "Step out",
313313 dap_next, "Step to next",
314− dap_variable_scopes, "List variable scopes",
314+ dap_variables, "List variables",
315315 dap_terminate, "End debug session",
316316 suspend, "Suspend"
317317 );
@@ -1910,53 +1910,6 @@ mod cmd {
19101910 Ok(())
19111911 }
19121912
1913− fn variables(
1914− cx: &mut compositor::Context,
1915− args: &[&str],
1916− _event: PromptEvent,
1917− ) -> anyhow::Result<()> {
1918− use helix_lsp::block_on;
1919−
1920− let scope = args.get(0).and_then(|arg| arg.parse::<usize>().ok());
1921− if scope.is_none() {
1922− cx.editor.set_status("Please provide scope ID".to_owned());
1923− return Ok(());
1924− }
1925−
1926− if let Some(debugger) = &mut cx.editor.debugger {
1927− if debugger.is_running {
1928− cx.editor
1929− .set_status("Cannot access variables while target is running".to_owned());
1930− return Ok(());
1931− }
1932− if debugger.stack_pointer.is_none() {
1933− cx.editor
1934− .set_status("Cannot find current stack pointer to access variables".to_owned());
1935− return Ok(());
1936− }
1937−
1938− let response = block_on(debugger.variables(scope.unwrap()));
1939−
1940− let status = match response {
1941− Ok(vars) => {
1942− let mut s = String::new();
1943− for var in vars {
1944− let prefix = match var.data_type {
1945− Some(data_type) => format!("{} ", data_type),
1946− None => "".to_owned(),
1947− };
1948− s.push_str(&format!("{}{} = {}; ", prefix, var.name, var.value));
1949− }
1950− s
1951− }
1952− Err(_) => "Failed to get variables".to_owned(),
1953− };
1954−
1955− cx.editor.set_status(status);
1956− }
1957− Ok(())
1958− }
1959−
19601913 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
19611914 TypableCommand {
19621915 name: "quit",
@@ -2195,13 +2148,6 @@ mod cmd {
21952148 doc: "Display tree sitter scopes, primarily for theming and development.",
21962149 fun: tree_sitter_scopes,
21972150 completer: None,
2198− },
2199− TypableCommand {
2200− name: "variables",
2201− alias: None,
2202− doc: "Display variables of scope. Get scope names using a command in debug menu",
2203− fun: variables,
2204− completer: None,
22052151 }
22062152 ];
22072153
@@ -4466,7 +4412,7 @@ fn dap_next(cx: &mut Context) {
44664412 }
44674413}
44684414
4469−fn dap_variable_scopes(cx: &mut Context) {
4415+fn dap_variables(cx: &mut Context) {
44704416 use helix_lsp::block_on;
44714417
44724418 if let Some(debugger) = &mut cx.editor.debugger {
@@ -4483,12 +4429,22 @@ fn dap_variable_scopes(cx: &mut Context) {
44834429
44844430 let frame_id = debugger.stack_pointer.clone().unwrap().id;
44854431 let scopes = block_on(debugger.scopes(frame_id)).unwrap();
4432+ let mut s = String::new();
44864433
4487− let mut status = String::new();
44884434 for scope in scopes.iter() {
4489− status.push_str(&format!("{}: {}; ", scope.variables_reference, scope.name))
4435+ let response = block_on(debugger.variables(scope.variables_reference));
4436+
4437+ if let Ok(vars) = response {
4438+ for var in vars {
4439+ let prefix = match var.data_type {
4440+ Some(data_type) => format!("{} ", data_type),
4441+ None => "".to_owned(),
4442+ };
4443+ s.push_str(&format!("{}{} = {}; ", prefix, var.name, var.value));
4444+ }
4445+ }
44904446 }
4491− cx.editor.set_status(status);
4447+ cx.editor.set_status(s);
44924448 }
44934449}
44944450
helix-term/src/keymap.rs+1−1
@@ -494,7 +494,7 @@ impl Default for Keymaps {
494494 "j" => dap_in,
495495 "k" => dap_out,
496496 "l" => dap_next,
497− "z" => dap_variable_scopes,
497+ "v" => dap_variables,
498498 "t" => dap_terminate,
499499 },
500500 "w" => { "Window"