Skip to content

Commit 25122e9

Browse files
committed
When the built-in $null was watched its value was incorrect
This fixes the evaluation of `$null` itself and variables that don't exist such that they display correctly in the watched variables pane of the debugger. As noted, the issue was that we were doing a string join even for a single (potentially null) value. This also fixes the excess quotes bug around a single value.
1 parent 6133c79 commit 25122e9

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

Diff for: src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,15 @@ public async Task<VariableDetails> EvaluateExpressionAsync(
527527
return null;
528528
}
529529

530-
// If we didn't write output,
531-
// return a VariableDetails instance.
530+
// If we didn't write output, return a VariableDetails instance.
532531
return new VariableDetails(
533-
expressionString,
534-
string.Join(Environment.NewLine, results));
532+
expressionString,
533+
// If there's only one result, we want its raw value (especially if it's null). For
534+
// a collection, since we're displaying these, we want to concatenante them.
535+
// However, doing that for one result caused null to be turned into an empty string.
536+
results.Count == 1
537+
? results[0]
538+
: string.Join(Environment.NewLine, results));
535539
}
536540

537541
/// <summary>

Diff for: src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DebugEvaluateHandler.cs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ internal class DebugEvaluateHandler : IEvaluateHandler
2222
private readonly IInternalPowerShellExecutionService _executionService;
2323
private readonly DebugService _debugService;
2424

25+
// AKA Watch Variables
2526
public DebugEvaluateHandler(
2627
ILoggerFactory factory,
2728
IPowerShellDebugContext debugContext,

Diff for: test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ await debugService.SetCommandBreakpointsAsync(
529529
AssertDebuggerStopped(testScript.FilePath, 11);
530530

531531
VariableDetails prompt = await debugService.EvaluateExpressionAsync("prompt", false, CancellationToken.None);
532-
Assert.Equal("\"True > \"", prompt.ValueString);
532+
Assert.Equal("True > ", prompt.ValueString);
533533
}
534534

535535
[SkippableFact]

0 commit comments

Comments
 (0)