@@ -307,6 +307,7 @@ impl Command {
307 dap_start, "Start debug session",
307 dap_start, "Start debug session",
308 dap_run, "Begin program execution",
308 dap_run, "Begin program execution",
309 dap_continue, "Continue program execution",
309 dap_continue, "Continue program execution",
310+ dap_variable_scopes, "List variable scopes",
310 dap_terminate, "End debug session",
311 dap_terminate, "End debug session",
311 suspend, "Suspend"
312 suspend, "Suspend"
@@ -1905,6 +1906,49 @@ mod cmd {
1910+ cx: &mut compositor::Context,
1912+ _event: PromptEvent,
1913+ ) -> anyhow::Result<()> {
1914+ use helix_lsp::block_on;
1916+ let scope = args.get(0).and_then(|arg| arg.parse::<usize>().ok());
1917+ if scope.is_none() {
1918+ cx.editor.set_status("Please provide scope ID".to_owned());
1922+ if let Some(debugger) = &mut cx.editor.debugger {
1923+ if debugger.is_running {
1925+ .set_status("Cannot access variables while target is running".to_owned());
1928+ if debugger.stack_pointer.is_none() {
1930+ .set_status("Cannot find current stack pointer to access variables".to_owned());
1934+ let response = block_on(debugger.variables(scope.unwrap()));
1936+ let status = match response {
1938+ let mut s = String::new();
1940+ s.push_str(&format!("{} = {}; ", var.name, var.value));
1944+ Err(_) => "Failed to get variables".to_owned(),
1947+ cx.editor.set_status(status);
1908 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
1952 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
1909 TypableCommand {
1953 TypableCommand {
1910 name: "quit",
1954 name: "quit",
@@ -2143,6 +2187,13 @@ mod cmd {
2143 doc: "Display tree sitter scopes, primarily for theming and development.",
2187 doc: "Display tree sitter scopes, primarily for theming and development.",
2144 fun: tree_sitter_scopes,
2188 fun: tree_sitter_scopes,
2145 completer: None,
2189 completer: None,
2194+ doc: "Display variables of scope. Get scope names using a command in debug menu",
@@ -4348,6 +4399,32 @@ fn dap_continue(cx: &mut Context) {
4402+fn dap_variable_scopes(cx: &mut Context) {
4403+ use helix_lsp::block_on;
4405+ if let Some(debugger) = &mut cx.editor.debugger {
4406+ if debugger.is_running {
4408+ .set_status("Cannot access variables while target is running".to_owned());
4411+ if debugger.stack_pointer.is_none() {
4413+ .set_status("Cannot find current stack pointer to access variables".to_owned());
4417+ let frame_id = debugger.stack_pointer.clone().unwrap().id;
4418+ let scopes = block_on(debugger.scopes(frame_id)).unwrap();
4420+ let mut status = String::new();
4421+ for scope in scopes.iter() {
4422+ status.push_str(&format!("{}: {}; ", scope.variables_reference, scope.name))
4424+ cx.editor.set_status(status);
4351fn dap_terminate(cx: &mut Context) {
4428fn dap_terminate(cx: &mut Context) {
4352 use helix_lsp::block_on;
4429 use helix_lsp::block_on;