Skip to content

Fix issue w/Auto variables empty in script scope. #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions src/PowerShellEditorServices/Debugging/DebugService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,25 @@ private async Task<VariableContainerDetails> 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"))
Expand All @@ -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("_"))
{
Expand All @@ -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))
Expand All @@ -775,11 +782,6 @@ private bool AddToAutoVariables(PSObject psvariable, string scope)
}
}

if (variableValue != null && variableValue.GetType().Name.EndsWith(nameof(PSDebugContext)))
{
return false;
}

return true;
}

Expand Down