From 2b7d4d8b706e687d2823bcaca8e4c066d073994d Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sat, 25 Mar 2017 21:45:52 -0600 Subject: [PATCH] Fix issue w/Auto variables empty in script scope. --- .../Debugging/DebugService.cs | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/PowerShellEditorServices/Debugging/DebugService.cs b/src/PowerShellEditorServices/Debugging/DebugService.cs index 81d042eea..e601d2037 100644 --- a/src/PowerShellEditorServices/Debugging/DebugService.cs +++ b/src/PowerShellEditorServices/Debugging/DebugService.cs @@ -712,9 +712,25 @@ private async Task FetchVariableContainer( private bool AddToAutoVariables(PSObject psvariable, string scope) { + if ((scope == VariableContainerDetails.GlobalScopeName) || + (scope == VariableContainerDetails.ScriptScopeName)) + { + // We don't A) have a good way of distinguishing built-in from user created variables + // and B) globalScopeVariables.Children.ContainsKey() doesn't work for built-in variables + // stored in a child variable container within the globals variable container. + return false; + } + string variableName = psvariable.Properties["Name"].Value as string; object variableValue = psvariable.Properties["Value"].Value; + // Don't put any variables created by PSES in the Auto variable container. + if (variableName.StartsWith(PsesGlobalVariableNamePrefix) || + variableName.Equals("PSDebugContext")) + { + return false; + } + ScopedItemOptions variableScope = ScopedItemOptions.None; PSPropertyInfo optionsProperty = psvariable.Properties["Options"]; if (string.Equals(optionsProperty.TypeNameOfValue, "System.String")) @@ -733,20 +749,8 @@ private bool AddToAutoVariables(PSObject psvariable, string scope) variableScope = (ScopedItemOptions)optionsProperty.Value; } - if ((scope == VariableContainerDetails.GlobalScopeName) || - (scope == VariableContainerDetails.ScriptScopeName)) - { - // We don't A) have a good way of distinguishing built-in from user created variables - // and B) globalScopeVariables.Children.ContainsKey() doesn't work for built-in variables - // stored in a child variable container within the globals variable container. - return false; - } - - var constantAllScope = ScopedItemOptions.AllScope | ScopedItemOptions.Constant; - var readonlyAllScope = ScopedItemOptions.AllScope | ScopedItemOptions.ReadOnly; - // Some local variables, if they exist, should be displayed by default - if (psvariable.TypeNames.Any(typeName => typeName.EndsWith("LocalVariable"))) + if (psvariable.TypeNames[0].EndsWith("LocalVariable")) { if (variableName.Equals("_")) { @@ -760,13 +764,16 @@ private bool AddToAutoVariables(PSObject psvariable, string scope) return false; } - else if (!psvariable.TypeNames.Any(typeName => typeName.EndsWith("PSVariable"))) + else if (!psvariable.TypeNames[0].EndsWith(nameof(PSVariable))) { return false; } - if (((variableScope | constantAllScope) == constantAllScope) || - ((variableScope | readonlyAllScope) == readonlyAllScope)) + var constantAllScope = ScopedItemOptions.AllScope | ScopedItemOptions.Constant; + var readonlyAllScope = ScopedItemOptions.AllScope | ScopedItemOptions.ReadOnly; + + if (((variableScope & constantAllScope) == constantAllScope) || + ((variableScope & readonlyAllScope) == readonlyAllScope)) { string prefixedVariableName = VariableDetails.DollarPrefix + variableName; if (this.globalScopeVariables.Children.ContainsKey(prefixedVariableName)) @@ -775,11 +782,6 @@ private bool AddToAutoVariables(PSObject psvariable, string scope) } } - if (variableValue != null && variableValue.GetType().Name.EndsWith(nameof(PSDebugContext))) - { - return false; - } - return true; }