@@ -270,9 +270,11 @@ public StackFrameDetails[] GetStackFrames()
270
270
public VariableScope [ ] GetVariableScopes ( int stackFrameId )
271
271
{
272
272
int localStackFrameVariableId = this . stackFrameDetails [ stackFrameId ] . LocalVariables . Id ;
273
+ int autoVariablesId = this . stackFrameDetails [ stackFrameId ] . AutoVariables . Id ;
273
274
274
275
return new VariableScope [ ]
275
276
{
277
+ new VariableScope ( autoVariablesId , VariableContainerDetails . AutoVariablesName ) ,
276
278
new VariableScope ( localStackFrameVariableId , VariableContainerDetails . LocalScopeName ) ,
277
279
new VariableScope ( this . scriptScopeVariables . Id , VariableContainerDetails . ScriptScopeName ) ,
278
280
new VariableScope ( this . globalScopeVariables . Id , VariableContainerDetails . GlobalScopeName ) ,
@@ -321,11 +323,13 @@ private async Task FetchStackFramesAndVariables()
321
323
private async Task FetchGlobalAndScriptVariables ( )
322
324
{
323
325
// Retrieve globals first as script variable retrieval needs to search globals.
324
- this . globalScopeVariables = await FetchVariableContainer ( VariableContainerDetails . GlobalScopeName ) ;
325
- this . scriptScopeVariables = await FetchVariableContainer ( VariableContainerDetails . ScriptScopeName ) ;
326
+ this . globalScopeVariables = await FetchVariableContainer ( VariableContainerDetails . GlobalScopeName , null ) ;
327
+ this . scriptScopeVariables = await FetchVariableContainer ( VariableContainerDetails . ScriptScopeName , null ) ;
326
328
}
327
329
328
- private async Task < VariableContainerDetails > FetchVariableContainer ( string scope )
330
+ private async Task < VariableContainerDetails > FetchVariableContainer (
331
+ string scope ,
332
+ VariableContainerDetails autoVariables )
329
333
{
330
334
PSCommand psCommand = new PSCommand ( ) ;
331
335
psCommand . AddCommand ( "Get-Variable" ) ;
@@ -335,52 +339,38 @@ private async Task<VariableContainerDetails> FetchVariableContainer(string scope
335
339
new VariableContainerDetails ( this . nextVariableId ++ , "Scope: " + scope ) ;
336
340
this . variables . Add ( scopeVariableContainer ) ;
337
341
338
-
339
- // Add a container node to this variable container that will "hide" the built-in,
340
- // automatic variables that we usually aren't interested in. Do this for local and script scope.
341
- VariableContainerDetails automaticVariableContainer = null ;
342
- if ( scope != VariableContainerDetails . GlobalScopeName )
343
- {
344
- automaticVariableContainer =
345
- new VariableContainerDetails ( this . nextVariableId ++ , "Automatic Variables" ) ;
346
- this . variables . Add ( automaticVariableContainer ) ;
347
- scopeVariableContainer . Children . Add ( automaticVariableContainer . Name , automaticVariableContainer ) ;
348
- }
349
-
350
342
var results = await this . powerShellContext . ExecuteCommand < PSVariable > ( psCommand ) ;
351
343
foreach ( PSVariable psvariable in results )
352
344
{
353
345
var variableDetails = new VariableDetails ( psvariable ) { Id = this . nextVariableId ++ } ;
354
346
this . variables . Add ( variableDetails ) ;
347
+ scopeVariableContainer . Children . Add ( variableDetails . Name , variableDetails ) ;
355
348
356
- if ( ( automaticVariableContainer == null ) || ShouldAlwaysDisplayVariable ( psvariable , scope ) )
357
- {
358
- scopeVariableContainer . Children . Add ( variableDetails . Name , variableDetails ) ;
359
- }
360
- else
349
+ if ( ( autoVariables != null ) && AddToAutoVariables ( psvariable , scope ) )
361
350
{
362
- automaticVariableContainer . Children . Add ( variableDetails . Name , variableDetails ) ;
351
+ autoVariables . Children . Add ( variableDetails . Name , variableDetails ) ;
363
352
}
364
353
}
365
354
366
355
return scopeVariableContainer ;
367
356
}
368
357
369
- private bool ShouldAlwaysDisplayVariable ( PSVariable psvariable , string scope )
358
+ private bool AddToAutoVariables ( PSVariable psvariable , string scope )
370
359
{
371
- ScopedItemOptions constantAllScope = ScopedItemOptions . AllScope | ScopedItemOptions . Constant ;
372
- ScopedItemOptions readonlyAllScope = ScopedItemOptions . AllScope | ScopedItemOptions . ReadOnly ;
373
-
374
- if ( scope == VariableContainerDetails . GlobalScopeName )
360
+ if ( ( scope == VariableContainerDetails . GlobalScopeName ) ||
361
+ ( scope == VariableContainerDetails . ScriptScopeName ) )
375
362
{
376
- // We don't A) have a good way of distinguishing automatic from user created variabbles
377
- // and B) globalScopeVariables.Children.ContainsKey() doesn't work for automatic variables
363
+ // We don't A) have a good way of distinguishing built-in from user created variables
364
+ // and B) globalScopeVariables.Children.ContainsKey() doesn't work for built-in variables
378
365
// stored in a child variable container within the globals variable container.
379
- return true ;
366
+ return false ;
380
367
}
381
368
369
+ var constantAllScope = ScopedItemOptions . AllScope | ScopedItemOptions . Constant ;
370
+ var readonlyAllScope = ScopedItemOptions . AllScope | ScopedItemOptions . ReadOnly ;
371
+
382
372
// Some local variables, if they exist, should be displayed by default
383
- if ( psvariable . GetType ( ) . Name == "LocalVariable" )
373
+ if ( psvariable . GetType ( ) . Name == "LocalVariable" )
384
374
{
385
375
if ( psvariable . Name . Equals ( "_" ) )
386
376
{
@@ -428,9 +418,18 @@ private async Task FetchStackFrames()
428
418
429
419
for ( int i = 0 ; i < callStackFrames . Length ; i ++ )
430
420
{
431
- VariableContainerDetails localVariables =
432
- await FetchVariableContainer ( i . ToString ( ) ) ;
433
- this . stackFrameDetails [ i ] = StackFrameDetails . Create ( callStackFrames [ i ] , localVariables ) ;
421
+ VariableContainerDetails autoVariables =
422
+ new VariableContainerDetails (
423
+ this . nextVariableId ++ ,
424
+ VariableContainerDetails . AutoVariablesName ) ;
425
+
426
+ this . variables . Add ( autoVariables ) ;
427
+
428
+ VariableContainerDetails localVariables =
429
+ await FetchVariableContainer ( i . ToString ( ) , autoVariables ) ;
430
+
431
+ this . stackFrameDetails [ i ] =
432
+ StackFrameDetails . Create ( callStackFrames [ i ] , autoVariables , localVariables ) ;
434
433
}
435
434
}
436
435
0 commit comments