Fix only allow autocompletion for variables that are from the current(first) stackframe
So this changes the behavior for providing variables for autocompletion inside the debug console if the adapter does not support autocompletion. Before this change you would get variables based on the selected stack frame. But this is not correct, as you cannot use variables that are not in scope anymore. So changing it to only provide variables for the current(first) stack frame we should provide variables that could always be used for autocompletion and for expressions.
This commit is contained in:
@@ -406,7 +406,9 @@ impl ConsoleQueryBarCompletionProvider {
|
||||
let mut variables = HashMap::new();
|
||||
let mut string_matches = Vec::new();
|
||||
|
||||
for variable in console.variable_list.update(cx, |v, cx| v.variables(cx)) {
|
||||
for variable in console.variable_list.update(cx, |variable_list, cx| {
|
||||
variable_list.completion_variables(cx)
|
||||
}) {
|
||||
if let Some(evaluate_name) = &variable.variable.evaluate_name {
|
||||
variables.insert(evaluate_name.clone(), variable.variable.value.clone());
|
||||
string_matches.push(StringMatchCandidate {
|
||||
|
||||
@@ -109,6 +109,13 @@ impl StackFrameList {
|
||||
&self.stack_frames
|
||||
}
|
||||
|
||||
pub fn first_stack_frame_id(&self) -> u64 {
|
||||
self.stack_frames
|
||||
.first()
|
||||
.map(|stack_frame| stack_frame.id)
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
pub fn current_stack_frame_id(&self) -> u64 {
|
||||
self.current_stack_frame_id
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ async fn test_basic_fetch_initial_scope_and_variables(
|
||||
depth: 1,
|
||||
},
|
||||
],
|
||||
variable_list.variables(cx)
|
||||
variable_list.variables_by_stack_frame_id(1)
|
||||
);
|
||||
|
||||
variable_list.assert_visual_entries(
|
||||
|
||||
@@ -591,8 +591,19 @@ impl VariableList {
|
||||
self.variables.get(&(stack_frame_id, scope_id))
|
||||
}
|
||||
|
||||
pub fn variables(&self, cx: &mut ViewContext<Self>) -> Vec<VariableContainer> {
|
||||
let stack_frame_id = self.stack_frame_list.read(cx).current_stack_frame_id();
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub fn variables_by_stack_frame_id(
|
||||
&self,
|
||||
stack_frame_id: StackFrameId,
|
||||
) -> Vec<VariableContainer> {
|
||||
self.variables
|
||||
.range((stack_frame_id, u64::MIN)..(stack_frame_id, u64::MAX))
|
||||
.flat_map(|(_, containers)| containers.variables.iter().cloned())
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn completion_variables(&self, cx: &mut ViewContext<Self>) -> Vec<VariableContainer> {
|
||||
let stack_frame_id = self.stack_frame_list.read(cx).first_stack_frame_id();
|
||||
|
||||
self.variables
|
||||
.range((stack_frame_id, u64::MIN)..(stack_frame_id, u64::MAX))
|
||||
|
||||
Reference in New Issue
Block a user