Skip to content

Commit edca175

Browse files
rkeithhilldaviwil
authored andcommitted
Fix vscode-powershell issue 872 - watch expandable variables can't be expanded.
1 parent ec398a0 commit edca175

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -787,17 +787,25 @@ protected async Task HandleEvaluateRequest(
787787
}
788788
else
789789
{
790-
VariableDetails result = null;
790+
VariableDetailsBase result = null;
791791

792792
// VS Code might send this request after the debugger
793793
// has been resumed, return an empty result in this case.
794794
if (editorSession.PowerShellContext.IsDebuggerStopped)
795795
{
796+
// First check to see if the watch expression refers to a naked variable reference.
796797
result =
797-
await editorSession.DebugService.EvaluateExpression(
798-
evaluateParams.Expression,
799-
evaluateParams.FrameId,
800-
isFromRepl);
798+
editorSession.DebugService.GetVariableFromExpression(evaluateParams.Expression, evaluateParams.FrameId);
799+
800+
// If the expression is not a naked variable reference, then evaluate the expression.
801+
if (result == null)
802+
{
803+
result =
804+
await editorSession.DebugService.EvaluateExpression(
805+
evaluateParams.Expression,
806+
evaluateParams.FrameId,
807+
isFromRepl);
808+
}
801809
}
802810

803811
if (result != null)

src/PowerShellEditorServices/Debugging/DebugService.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,11 @@ public VariableDetailsBase[] GetVariables(int variableReferenceId)
395395
/// <returns>A VariableDetailsBase object containing the result.</returns>
396396
public VariableDetailsBase GetVariableFromExpression(string variableExpression, int stackFrameId)
397397
{
398+
// NOTE: From a watch we will get passed expressions that are not naked variables references.
399+
// Probably the right way to do this woudld be to examine the AST of the expr before calling
400+
// this method to make sure it is a VariableReference. But for the most part, non-naked variable
401+
// references are very unlikely to find a matching variable e.g. "$i+5.2" will find no var matching "$i+5".
402+
398403
// Break up the variable path
399404
string[] variablePathParts = variableExpression.Split('.');
400405

@@ -414,7 +419,7 @@ public VariableDetailsBase GetVariableFromExpression(string variableExpression,
414419
v =>
415420
string.Equals(
416421
v.Name,
417-
variableExpression,
422+
variableName,
418423
StringComparison.CurrentCultureIgnoreCase));
419424

420425
if (resolvedVariable != null &&

0 commit comments

Comments
 (0)