@@ -712,9 +712,25 @@ private async Task<VariableContainerDetails> FetchVariableContainer(
712
712
713
713
private bool AddToAutoVariables ( PSObject psvariable , string scope )
714
714
{
715
+ if ( ( scope == VariableContainerDetails . GlobalScopeName ) ||
716
+ ( scope == VariableContainerDetails . ScriptScopeName ) )
717
+ {
718
+ // We don't A) have a good way of distinguishing built-in from user created variables
719
+ // and B) globalScopeVariables.Children.ContainsKey() doesn't work for built-in variables
720
+ // stored in a child variable container within the globals variable container.
721
+ return false ;
722
+ }
723
+
715
724
string variableName = psvariable . Properties [ "Name" ] . Value as string ;
716
725
object variableValue = psvariable . Properties [ "Value" ] . Value ;
717
726
727
+ // Don't put any variables created by PSES in the Auto variable container.
728
+ if ( variableName . StartsWith ( PsesGlobalVariableNamePrefix ) ||
729
+ variableName . Equals ( "PSDebugContext" ) )
730
+ {
731
+ return false ;
732
+ }
733
+
718
734
ScopedItemOptions variableScope = ScopedItemOptions . None ;
719
735
PSPropertyInfo optionsProperty = psvariable . Properties [ "Options" ] ;
720
736
if ( string . Equals ( optionsProperty . TypeNameOfValue , "System.String" ) )
@@ -733,20 +749,8 @@ private bool AddToAutoVariables(PSObject psvariable, string scope)
733
749
variableScope = ( ScopedItemOptions ) optionsProperty . Value ;
734
750
}
735
751
736
- if ( ( scope == VariableContainerDetails . GlobalScopeName ) ||
737
- ( scope == VariableContainerDetails . ScriptScopeName ) )
738
- {
739
- // We don't A) have a good way of distinguishing built-in from user created variables
740
- // and B) globalScopeVariables.Children.ContainsKey() doesn't work for built-in variables
741
- // stored in a child variable container within the globals variable container.
742
- return false ;
743
- }
744
-
745
- var constantAllScope = ScopedItemOptions . AllScope | ScopedItemOptions . Constant ;
746
- var readonlyAllScope = ScopedItemOptions . AllScope | ScopedItemOptions . ReadOnly ;
747
-
748
752
// Some local variables, if they exist, should be displayed by default
749
- if ( psvariable . TypeNames . Any ( typeName => typeName . EndsWith ( "LocalVariable" ) ) )
753
+ if ( psvariable . TypeNames [ 0 ] . EndsWith ( "LocalVariable" ) )
750
754
{
751
755
if ( variableName . Equals ( "_" ) )
752
756
{
@@ -760,13 +764,16 @@ private bool AddToAutoVariables(PSObject psvariable, string scope)
760
764
761
765
return false ;
762
766
}
763
- else if ( ! psvariable . TypeNames . Any ( typeName => typeName . EndsWith ( " PSVariable" ) ) )
767
+ else if ( ! psvariable . TypeNames [ 0 ] . EndsWith ( nameof ( PSVariable ) ) )
764
768
{
765
769
return false ;
766
770
}
767
771
768
- if ( ( ( variableScope | constantAllScope ) == constantAllScope ) ||
769
- ( ( variableScope | readonlyAllScope ) == readonlyAllScope ) )
772
+ var constantAllScope = ScopedItemOptions . AllScope | ScopedItemOptions . Constant ;
773
+ var readonlyAllScope = ScopedItemOptions . AllScope | ScopedItemOptions . ReadOnly ;
774
+
775
+ if ( ( ( variableScope & constantAllScope ) == constantAllScope ) ||
776
+ ( ( variableScope & readonlyAllScope ) == readonlyAllScope ) )
770
777
{
771
778
string prefixedVariableName = VariableDetails . DollarPrefix + variableName ;
772
779
if ( this . globalScopeVariables . Children . ContainsKey ( prefixedVariableName ) )
@@ -775,11 +782,6 @@ private bool AddToAutoVariables(PSObject psvariable, string scope)
775
782
}
776
783
}
777
784
778
- if ( variableValue != null && variableValue . GetType ( ) . Name . EndsWith ( nameof ( PSDebugContext ) ) )
779
- {
780
- return false ;
781
- }
782
-
783
785
return true ;
784
786
}
785
787
0 commit comments