Skip to content

Commit 3509712

Browse files
JustinGroteSeeminglyScienceandyleejordan
committed
Add magic value formatting for booleans
Co-authored-by: Patrick Meinecke <[email protected]> Co-authored-by: Andy Schwartzmeyer <[email protected]>
1 parent 2f93b7b commit 3509712

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetails.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,22 @@ private static string GetValueStringAndType(object value, bool isExpandable, out
168168
}
169169

170170
Type objType = value.GetType();
171-
typeName = $"[{objType.FullName}]";
171+
172+
// This is the type format PowerShell users expect and will appear when you hover a variable name
173+
typeName = '[' + objType.FullName + ']';
172174

173175
if (value is bool)
174176
{
175177
// Set to identifier recognized by PowerShell to make setVariable from the debug UI more natural.
176178
valueString = (bool) value ? "$true" : "$false";
179+
180+
// We need to use this "magic value" to highlight in vscode properly
181+
// These "magic values" are analagous to TypeScript and are visible in VSCode here:
182+
// https://github.com/microsoft/vscode/blob/57ca9b99d5b6a59f2d2e0f082ae186559f45f1d8/src/vs/workbench/contrib/debug/browser/baseDebugView.ts#L68-L78
183+
// NOTE: we don't do numbers and strings since they (so far) seem to get detected properly by
184+
//serialization, and the original .NET type can be preserved so it shows up in the variable name
185+
//type hover as the original .NET type.
186+
typeName = "boolean";
177187
}
178188
else if (isExpandable)
179189
{

test/PowerShellEditorServices.Test.Shared/Debugging/VariableTest.ps1

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
class MyClass {
2-
[String] $Name;
3-
[Int32] $Number; }
2+
[String] $Name;
3+
[Int32] $Number; }
44
[bool]$scriptBool = $false
55
$scriptInt = 42
66
function Test-Variables {
77
$strVar = "Hello"
8-
[string]$strVar2 = "Hello2"
9-
$arrVar = @(1, 2, $strVar, $objVar)
10-
$assocArrVar = @{ firstChild = "Child"; secondChild = 42 }
11-
$classVar = [MyClass]::new();
12-
$classVar.Name = "Test"
13-
$classVar.Number = 42;
8+
[string]$strVar2 = "Hello2"
9+
$arrVar = @(1, 2, $strVar, $objVar)
10+
$assocArrVar = @{ firstChild = "Child"; secondChild = 42 }
11+
$classVar = [MyClass]::new();
12+
$classVar.Name = "Test"
13+
$classVar.Number = 42;
1414
$enumVar = $ErrorActionPreference
1515
$nullString = [NullString]::Value
16-
$psObjVar = New-Object -TypeName PSObject -Property @{Name = 'John'; Age = 75}
17-
$psCustomObjVar = [PSCustomObject] @{Name = 'Paul'; Age = 73}
16+
$psObjVar = New-Object -TypeName PSObject -Property @{Name = 'John'; Age = 75 }
17+
$psCustomObjVar = [PSCustomObject] @{Name = 'Paul'; Age = 73 }
1818
$procVar = Get-Process -PID $PID
19-
Write-Output "Done"
19+
$trueVar = $true
20+
$falseVar = $false
21+
Write-Output "Done"
2022
}
2123

2224
Test-Variables

test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ public async Task DebuggerGetsVariables()
534534
{
535535
await debugService.SetLineBreakpointsAsync(
536536
variableScriptFile,
537-
new[] { BreakpointDetails.Create(variableScriptFile.FilePath, 14) }).ConfigureAwait(true);
537+
new[] { BreakpointDetails.Create(variableScriptFile.FilePath, 21) }).ConfigureAwait(true);
538538

539539
Task _ = ExecuteVariableScriptFile();
540540
AssertDebuggerStopped(variableScriptFile.FilePath);
@@ -567,6 +567,16 @@ await debugService.SetLineBreakpointsAsync(
567567

568568
var classChildren = debugService.GetVariables(classVar.Id);
569569
Assert.Equal(2, classChildren.Length);
570+
571+
var trueVar = Array.Find(variables, v => v.Name == "$trueVar");
572+
Assert.NotNull(trueVar);
573+
Assert.Equal("boolean", trueVar.Type);
574+
Assert.Equal("$true", trueVar.ValueString);
575+
576+
var falseVar = Array.Find(variables, v => v.Name == "$falseVar");
577+
Assert.NotNull(falseVar);
578+
Assert.Equal("boolean", falseVar.Type);
579+
Assert.Equal("$false", falseVar.ValueString);
570580
}
571581

572582
[Trait("Category", "DebugService")]

0 commit comments

Comments
 (0)