Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vscode-powershell issue 872 - watch expandable variables can't be… #534

Merged
merged 1 commit into from
Jun 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -787,17 +787,25 @@ protected async Task HandleEvaluateRequest(
}
else
{
VariableDetails result = null;
VariableDetailsBase result = null;

// VS Code might send this request after the debugger
// has been resumed, return an empty result in this case.
if (editorSession.PowerShellContext.IsDebuggerStopped)
{
// First check to see if the watch expression refers to a naked variable reference.
result =
await editorSession.DebugService.EvaluateExpression(
evaluateParams.Expression,
evaluateParams.FrameId,
isFromRepl);
editorSession.DebugService.GetVariableFromExpression(evaluateParams.Expression, evaluateParams.FrameId);

// If the expression is not a naked variable reference, then evaluate the expression.
if (result == null)
{
result =
await editorSession.DebugService.EvaluateExpression(
evaluateParams.Expression,
evaluateParams.FrameId,
isFromRepl);
}
}

if (result != null)
Expand Down
7 changes: 6 additions & 1 deletion src/PowerShellEditorServices/Debugging/DebugService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ public VariableDetailsBase[] GetVariables(int variableReferenceId)
/// <returns>A VariableDetailsBase object containing the result.</returns>
public VariableDetailsBase GetVariableFromExpression(string variableExpression, int stackFrameId)
{
// NOTE: From a watch we will get passed expressions that are not naked variables references.
// Probably the right way to do this woudld be to examine the AST of the expr before calling
// this method to make sure it is a VariableReference. But for the most part, non-naked variable
// references are very unlikely to find a matching variable e.g. "$i+5.2" will find no var matching "$i+5".

// Break up the variable path
string[] variablePathParts = variableExpression.Split('.');

Expand All @@ -414,7 +419,7 @@ public VariableDetailsBase GetVariableFromExpression(string variableExpression,
v =>
string.Equals(
v.Name,
variableExpression,
variableName,
StringComparison.CurrentCultureIgnoreCase));

if (resolvedVariable != null &&
Expand Down