Skip to content

Commit 1769cc9

Browse files
Get variable info of children
1 parent 36ec556 commit 1769cc9

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/extension/debugger/inlineValue/pythonInlineValueProvider.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,17 @@ export class PythonInlineValueProvider implements InlineValuesProvider {
6565
'self',
6666
];
6767

68-
const pythonVariables: any[] = variablesRequest.variables
68+
let includeTypes = ['int', 'float', 'str', 'list', 'dict', 'tuple', 'set', 'bool'];
69+
70+
const pythonVariables = variablesRequest.variables
6971
.filter((variable: any) => variable.type)
70-
.map((variable: any) => variable.name);
72+
.reduce((acc: { [key: string]: any }, variable: any) => {
73+
acc[variable.name] = {
74+
type: variable.type,
75+
variablesReference: variable.variablesReference,
76+
};
77+
return acc;
78+
}, {});
7179

7280
let variableRegex = new RegExp(
7381
'(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*' + //match any number of variable names separated by '.'
@@ -91,13 +99,26 @@ export class PythonInlineValueProvider implements InlineValuesProvider {
9199
if (pythonKeywords.includes(varName)) {
92100
continue;
93101
}
94-
if (pythonVariables.includes(varName.split('.')[0])) {
102+
let baseVarName = varName.split('.')[0];
103+
if (pythonVariables.hasOwnProperty(baseVarName)) {
95104
if (varName.includes('.')) {
96-
const rng = new Range(l, match.index, l, match.index + varName.length);
97-
allValues.push(new InlineValueEvaluatableExpression(rng, varName));
105+
//Find variable name in the variable children
106+
let foundVariable = (
107+
await customRequest('variables', {
108+
variablesReference: pythonVariables[baseVarName].variablesReference,
109+
})
110+
).variables.find((variable: any) => variable.evaluateName === varName);
111+
//Check the type of the variable before adding to the inline values
112+
if (foundVariable && includeTypes.includes(foundVariable.type)) {
113+
const rng = new Range(l, match.index, l, match.index + varName.length);
114+
allValues.push(new InlineValueEvaluatableExpression(rng, varName));
115+
}
98116
} else {
99-
const rng = new Range(l, match.index, l, match.index + varName.length);
100-
allValues.push(new InlineValueVariableLookup(rng, varName, false));
117+
//Check the type of the variable before adding to the inline values
118+
if (includeTypes.includes(pythonVariables[baseVarName].type)) {
119+
const rng = new Range(l, match.index, l, match.index + varName.length);
120+
allValues.push(new InlineValueVariableLookup(rng, varName, false));
121+
}
101122
}
102123
}
103124
}

0 commit comments

Comments
 (0)