From 3dd91d5521304ec72eabf383179b5f5aa26bec4a Mon Sep 17 00:00:00 2001 From: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> Date: Fri, 10 Nov 2023 15:21:36 -0800 Subject: [PATCH] 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. --- .../Services/DebugAdapter/DebugService.cs | 12 ++++++++---- .../DebugAdapter/Handlers/DebugEvaluateHandler.cs | 1 + .../Debugging/DebugServiceTests.cs | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs b/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs index 43c54c17a..90faceda4 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs @@ -527,11 +527,15 @@ public async Task EvaluateExpressionAsync( return null; } - // If we didn't write output, - // return a VariableDetails instance. + // If we didn't write output, return a VariableDetails instance. return new VariableDetails( - expressionString, - string.Join(Environment.NewLine, results)); + expressionString, + // If there's only one result, we want its raw value (especially if it's null). For + // a collection, since we're displaying these, we want to concatenante them. + // However, doing that for one result caused null to be turned into an empty string. + results.Count == 1 + ? results[0] + : string.Join(Environment.NewLine, results)); } /// diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DebugEvaluateHandler.cs b/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DebugEvaluateHandler.cs index cd91809fd..78c55c1f1 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DebugEvaluateHandler.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DebugEvaluateHandler.cs @@ -22,6 +22,7 @@ internal class DebugEvaluateHandler : IEvaluateHandler private readonly IInternalPowerShellExecutionService _executionService; private readonly DebugService _debugService; + // AKA Watch Variables public DebugEvaluateHandler( ILoggerFactory factory, IPowerShellDebugContext debugContext, diff --git a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs index b6a1aa48d..30b020c30 100644 --- a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs +++ b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs @@ -529,7 +529,7 @@ await debugService.SetCommandBreakpointsAsync( AssertDebuggerStopped(testScript.FilePath, 11); VariableDetails prompt = await debugService.EvaluateExpressionAsync("prompt", false, CancellationToken.None); - Assert.Equal("\"True > \"", prompt.ValueString); + Assert.Equal("True > ", prompt.ValueString); } [SkippableFact]