on master help sign in
Simplify variables display
838f699Dmitry Sharshakov
helix-term/src/commands.rs+15−59
@@ -311,7 +311,7 @@ impl Command {
311 dap_in, "Step in",
311 dap_in, "Step in",
312 dap_out, "Step out",
312 dap_out, "Step out",
313 dap_next, "Step to next",
313 dap_next, "Step to next",
314− dap_variable_scopes, "List variable scopes",
314+ dap_variables, "List variables",
315 dap_terminate, "End debug session",
315 dap_terminate, "End debug session",
316 suspend, "Suspend"
316 suspend, "Suspend"
317 );
317 );
@@ -1910,53 +1910,6 @@ mod cmd {
1910 Ok(())
1910 Ok(())
1911 }
1911 }
1912
1912
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−
1960 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
1913 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
1961 TypableCommand {
1914 TypableCommand {
1962 name: "quit",
1915 name: "quit",
@@ -2195,13 +2148,6 @@ mod cmd {
2195 doc: "Display tree sitter scopes, primarily for theming and development.",
2148 doc: "Display tree sitter scopes, primarily for theming and development.",
2196 fun: tree_sitter_scopes,
2149 fun: tree_sitter_scopes,
2197 completer: None,
2150 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,
2205 }
2151 }
2206 ];
2152 ];
2207
2153
@@ -4466,7 +4412,7 @@ fn dap_next(cx: &mut Context) {
4466 }
4412 }
4467}
4413}
4468
4414
4469−fn dap_variable_scopes(cx: &mut Context) {
4415+fn dap_variables(cx: &mut Context) {
4470 use helix_lsp::block_on;
4416 use helix_lsp::block_on;
4471
4417
4472 if let Some(debugger) = &mut cx.editor.debugger {
4418 if let Some(debugger) = &mut cx.editor.debugger {
@@ -4483,12 +4429,22 @@ fn dap_variable_scopes(cx: &mut Context) {
4483
4429
4484 let frame_id = debugger.stack_pointer.clone().unwrap().id;
4430 let frame_id = debugger.stack_pointer.clone().unwrap().id;
4485 let scopes = block_on(debugger.scopes(frame_id)).unwrap();
4431 let scopes = block_on(debugger.scopes(frame_id)).unwrap();
4432+ let mut s = String::new();
4486
4433
4487− let mut status = String::new();
4488 for scope in scopes.iter() {
4434 for scope in scopes.iter() {
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+ };
4489− status.push_str(&format!("{}: {}; ", scope.variables_reference, scope.name))
4443+ s.push_str(&format!("{}{} = {}; ", prefix, var.name, var.value));
4444+ }
4445+ }
4490 }
4446 }
4491− cx.editor.set_status(status);
4447+ cx.editor.set_status(s);
4492 }
4448 }
4493}
4449}
4494
4450
helix-term/src/keymap.rs+1−1
@@ -494,7 +494,7 @@ impl Default for Keymaps {
494 "j" => dap_in,
494 "j" => dap_in,
495 "k" => dap_out,
495 "k" => dap_out,
496 "l" => dap_next,
496 "l" => dap_next,
497− "z" => dap_variable_scopes,
497+ "v" => dap_variables,
498 "t" => dap_terminate,
498 "t" => dap_terminate,
499 },
499 },
500 "w" => { "Window"
500 "w" => { "Window"