From ba5dde55df04a5f0a9f8270e2f6ecd03d5db807d Mon Sep 17 00:00:00 2001 From: Tad Hardesty Date: Fri, 27 Nov 2020 17:43:07 -0800 Subject: [PATCH] Handle duplicate variable names (Auxtools) --- src/langserver/debugger/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/langserver/debugger/mod.rs b/src/langserver/debugger/mod.rs index bcac4204..009986f4 100644 --- a/src/langserver/debugger/mod.rs +++ b/src/langserver/debugger/mod.rs @@ -1197,13 +1197,18 @@ handle_request! { let aux_variables = auxtools.get_variables(auxtools_types::VariablesRef(params.variablesReference as i32))?; let mut variables = vec![]; - // TODO // If VSC receives two Variables with the same name, it only // displays the first one. Avert this by adding suffixes. + let mut seen = std::collections::HashMap::new(); for aux_var in aux_variables { + let name = match seen.entry(aux_var.name.clone()).and_modify(|e| *e += 1).or_default() { + 0 => aux_var.name, + n => format!("{} #{}", aux_var.name, n), + }; + variables.push(Variable { - name: aux_var.name, + name, value: aux_var.value, variablesReference: aux_var.variables.map(|x| x.0 as i64).unwrap_or(0), .. Default::default()