Skip to content

Commit dfb8199

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.
1 parent 6133c79 commit dfb8199

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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>

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,

0 commit comments

Comments
 (0)