@@ -65,9 +65,17 @@ export class PythonInlineValueProvider implements InlineValuesProvider {
65
65
'self' ,
66
66
] ;
67
67
68
- const pythonVariables : any [ ] = variablesRequest . variables
68
+ let includeTypes = [ 'int' , 'float' , 'str' , 'list' , 'dict' , 'tuple' , 'set' , 'bool' ] ;
69
+
70
+ const pythonVariables = variablesRequest . variables
69
71
. 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
+ } , { } ) ;
71
79
72
80
let variableRegex = new RegExp (
73
81
'(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*' + //match any number of variable names separated by '.'
@@ -91,13 +99,26 @@ export class PythonInlineValueProvider implements InlineValuesProvider {
91
99
if ( pythonKeywords . includes ( varName ) ) {
92
100
continue ;
93
101
}
94
- if ( pythonVariables . includes ( varName . split ( '.' ) [ 0 ] ) ) {
102
+ let baseVarName = varName . split ( '.' ) [ 0 ] ;
103
+ if ( pythonVariables . hasOwnProperty ( baseVarName ) ) {
95
104
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
+ }
98
116
} 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
+ }
101
122
}
102
123
}
103
124
}
0 commit comments