Skip to content

Add magic value formatting for variable booleans #1636

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
Dec 27, 2021
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,22 @@ private static string GetValueStringAndType(object value, bool isExpandable, out
}

Type objType = value.GetType();
typeName = $"[{objType.FullName}]";

// This is the type format PowerShell users expect and will appear when you hover a variable name
typeName = '[' + objType.FullName + ']';

if (value is bool)
{
// Set to identifier recognized by PowerShell to make setVariable from the debug UI more natural.
valueString = (bool) value ? "$true" : "$false";

// We need to use this "magic value" to highlight in vscode properly
// These "magic values" are analagous to TypeScript and are visible in VSCode here:
// https://github.com/microsoft/vscode/blob/57ca9b99d5b6a59f2d2e0f082ae186559f45f1d8/src/vs/workbench/contrib/debug/browser/baseDebugView.ts#L68-L78
// NOTE: we don't do numbers and strings since they (so far) seem to get detected properly by
//serialization, and the original .NET type can be preserved so it shows up in the variable name
//type hover as the original .NET type.
typeName = "boolean";
}
else if (isExpandable)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
class MyClass {
[String] $Name;
[Int32] $Number; }
[String] $Name;
[Int32] $Number; }
[bool]$scriptBool = $false
$scriptInt = 42
function Test-Variables {
$strVar = "Hello"
[string]$strVar2 = "Hello2"
$arrVar = @(1, 2, $strVar, $objVar)
$assocArrVar = @{ firstChild = "Child"; secondChild = 42 }
$classVar = [MyClass]::new();
$classVar.Name = "Test"
$classVar.Number = 42;
[string]$strVar2 = "Hello2"
$arrVar = @(1, 2, $strVar, $objVar)
$assocArrVar = @{ firstChild = "Child"; secondChild = 42 }
$classVar = [MyClass]::new();
$classVar.Name = "Test"
$classVar.Number = 42;
$enumVar = $ErrorActionPreference
$nullString = [NullString]::Value
$psObjVar = New-Object -TypeName PSObject -Property @{Name = 'John'; Age = 75}
$psCustomObjVar = [PSCustomObject] @{Name = 'Paul'; Age = 73}
$psObjVar = New-Object -TypeName PSObject -Property @{Name = 'John'; Age = 75 }
$psCustomObjVar = [PSCustomObject] @{Name = 'Paul'; Age = 73 }
$procVar = Get-Process -PID $PID
Write-Output "Done"
$trueVar = $true
$falseVar = $false
Write-Output "Done"
}

Test-Variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public async Task DebuggerGetsVariables()
{
await debugService.SetLineBreakpointsAsync(
variableScriptFile,
new[] { BreakpointDetails.Create(variableScriptFile.FilePath, 14) }).ConfigureAwait(true);
new[] { BreakpointDetails.Create(variableScriptFile.FilePath, 21) }).ConfigureAwait(true);

Task _ = ExecuteVariableScriptFile();
AssertDebuggerStopped(variableScriptFile.FilePath);
Expand Down Expand Up @@ -567,6 +567,16 @@ await debugService.SetLineBreakpointsAsync(

var classChildren = debugService.GetVariables(classVar.Id);
Assert.Equal(2, classChildren.Length);

var trueVar = Array.Find(variables, v => v.Name == "$trueVar");
Assert.NotNull(trueVar);
Assert.Equal("boolean", trueVar.Type);
Assert.Equal("$true", trueVar.ValueString);

var falseVar = Array.Find(variables, v => v.Name == "$falseVar");
Assert.NotNull(falseVar);
Assert.Equal("boolean", falseVar.Type);
Assert.Equal("$false", falseVar.ValueString);
}

[Trait("Category", "DebugService")]
Expand Down