diff --git a/crates/debugger_ui/src/session/running/console.rs b/crates/debugger_ui/src/session/running/console.rs index 29c1f6ef30..dacd826102 100644 --- a/crates/debugger_ui/src/session/running/console.rs +++ b/crates/debugger_ui/src/session/running/console.rs @@ -2,11 +2,13 @@ use super::{ stack_frame_list::{StackFrameList, StackFrameListEvent}, variable_list::VariableList, }; +use collections::HashMap; use dap::{OutputEvent, OutputEventGroup}; use editor::{ display_map::{Crease, CreaseId}, Anchor, CompletionProvider, Editor, EditorElement, EditorStyle, FoldPlaceholder, }; +use fuzzy::StringMatchCandidate; use gpui::{Context, Entity, Render, Subscription, Task, TextStyle, WeakEntity}; use language::{Buffer, CodeLabel, LanguageServerId}; use menu::Confirm; @@ -33,7 +35,7 @@ pub struct Console { query_bar: Entity, session: Entity, _subscriptions: Vec, - _variable_list: Entity, + variable_list: Entity, stack_frame_list: Entity, } @@ -99,7 +101,7 @@ impl Console { session, console, query_bar, - _variable_list: variable_list, + variable_list, _subscriptions, stack_frame_list, groups: Vec::default(), @@ -391,78 +393,74 @@ impl CompletionProvider for ConsoleQueryBarCompletionProvider { impl ConsoleQueryBarCompletionProvider { fn variable_list_completions( &self, - _console: &Entity, - _buffer: &Entity, - _buffer_position: language::Anchor, - _cx: &mut Context, + console: &Entity, + buffer: &Entity, + buffer_position: language::Anchor, + cx: &mut Context, ) -> gpui::Task>> { - unimplemented!("Need to fix this for the refactor"); - // let (variables, string_matches) = console.update(cx, |console, cx| { - // let mut variables = HashMap::new(); - // let mut string_matches = Vec::new(); + let (variables, string_matches) = console.update(cx, |console, cx| { + let mut variables = HashMap::new(); + let mut string_matches = Vec::new(); - // for variable in console.variable_list.update(cx, |variable_list, cx| { - // variable_list.completion_variables(cx) - // }) { - // if let Some(evaluate_name) = &variable.variable.dap.evaluate_name { - // variables.insert(evaluate_name.clone(), variable.variable.dap.value.clone()); - // string_matches.push(StringMatchCandidate { - // id: 0, - // string: evaluate_name.clone(), - // char_bag: evaluate_name.chars().collect(), - // }); - // } + for variable in console.variable_list.update(cx, |variable_list, cx| { + variable_list.completion_variables(cx) + }) { + if let Some(evaluate_name) = &variable.evaluate_name { + variables.insert(evaluate_name.clone(), variable.value.clone()); + string_matches.push(StringMatchCandidate { + id: 0, + string: evaluate_name.clone(), + char_bag: evaluate_name.chars().collect(), + }); + } - // variables.insert( - // variable.variable.dap.name.clone(), - // variable.variable.dap.value.clone(), - // ); + variables.insert(variable.name.clone(), variable.value.clone()); - // string_matches.push(StringMatchCandidate { - // id: 0, - // string: variable.variable.dap.name.clone(), - // char_bag: variable.variable.dap.name.chars().collect(), - // }); - // } + string_matches.push(StringMatchCandidate { + id: 0, + string: variable.name.clone(), + char_bag: variable.name.chars().collect(), + }); + } - // (variables, string_matches) - // }); + (variables, string_matches) + }); - // let query = buffer.read(cx).text(); + let query = buffer.read(cx).text(); - // cx.spawn(|_, cx| async move { - // let matches = fuzzy::match_strings( - // &string_matches, - // &query, - // true, - // 10, - // &Default::default(), - // cx.background_executor().clone(), - // ) - // .await; + cx.spawn(|_, cx| async move { + let matches = fuzzy::match_strings( + &string_matches, + &query, + true, + 10, + &Default::default(), + cx.background_executor().clone(), + ) + .await; - // Ok(matches - // .iter() - // .filter_map(|string_match| { - // let variable_value = variables.get(&string_match.string)?; + Ok(matches + .iter() + .filter_map(|string_match| { + let variable_value = variables.get(&string_match.string)?; - // Some(project::Completion { - // old_range: buffer_position..buffer_position, - // new_text: string_match.string.clone(), - // label: CodeLabel { - // filter_range: 0..string_match.string.len(), - // text: format!("{} {}", string_match.string.clone(), variable_value), - // runs: Vec::new(), - // }, - // server_id: LanguageServerId(usize::MAX), - // documentation: None, - // lsp_completion: Default::default(), - // confirm: None, - // resolved: true, - // }) - // }) - // .collect()) - // }) + Some(project::Completion { + old_range: buffer_position..buffer_position, + new_text: string_match.string.clone(), + label: CodeLabel { + filter_range: 0..string_match.string.len(), + text: format!("{} {}", string_match.string.clone(), variable_value), + runs: Vec::new(), + }, + server_id: LanguageServerId(usize::MAX), + documentation: None, + lsp_completion: Default::default(), + confirm: None, + resolved: true, + }) + }) + .collect()) + }) } fn client_completions( diff --git a/crates/debugger_ui/src/session/running/variable_list.rs b/crates/debugger_ui/src/session/running/variable_list.rs index 11306f96b9..e996f0537b 100644 --- a/crates/debugger_ui/src/session/running/variable_list.rs +++ b/crates/debugger_ui/src/session/running/variable_list.rs @@ -6,11 +6,7 @@ use gpui::{ ListState, MouseDownEvent, Point, Subscription, }; use project::debugger::session::Session; -use std::{ - collections::HashMap, - path::{Path, PathBuf}, - sync::Arc, -}; +use std::{collections::HashMap, sync::Arc}; use ui::{prelude::*, ContextMenu, ListItem}; use util::debug_panic; @@ -195,16 +191,17 @@ impl VariableList { } } - // pub fn completion_variables(&self, cx: &mut Context) -> Vec { - // let stack_frame_id = self - // .stack_frame_list - // .update(cx, |this, cx| this.get_main_stack_frame_id(cx)); - - // self.variables - // .range((stack_frame_id, u64::MIN)..(stack_frame_id, u64::MAX)) - // .flat_map(|(_, containers)| containers.variables.iter().cloned()) - // .collect() - // } + // debugger(todo): This only returns visible variables will need to change it to show all variables + // within a stack frame scope + pub fn completion_variables(&self, _cx: &mut Context) -> Vec { + self.entries + .iter() + .filter_map(|entry| match entry { + VariableListEntry::Variable((variable, ..)) => Some(variable.clone()), + _ => None, + }) + .collect() + } fn render_entry(&mut self, ix: usize, cx: &mut Context) -> AnyElement { let Some(entry) = self.entries.get(ix) else {