Skip to content

Commit de16d79

Browse files
committed
Fix SetVariableAsync for new local variable container
1 parent 557e7a8 commit de16d79

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
using System;
@@ -423,29 +423,23 @@ public async Task<string> SetVariableAsync(int variableContainerReferenceId, str
423423
}
424424

425425
VariableDetailsBase variable = variableContainer.Children[name];
426-
// Determine scope in which the variable lives. This is required later for the call to Get-Variable -Scope.
427-
string scope = null;
428-
if (variableContainerReferenceId == this.scriptScopeVariables.Id)
426+
// Determine scope in which the variable lives so we can pass it to `Get-Variable -Scope`.
427+
string scope = null; // TODO: Can this use a fancy pattern matcher?
428+
if (variableContainerReferenceId == localScopeVariables.Id)
429429
{
430-
scope = "Script";
430+
scope = VariableContainerDetails.LocalScopeName;
431431
}
432-
else if (variableContainerReferenceId == this.globalScopeVariables.Id)
432+
else if (variableContainerReferenceId == scriptScopeVariables.Id)
433433
{
434-
scope = "Global";
434+
scope = VariableContainerDetails.ScriptScopeName;
435435
}
436-
else
436+
else if (variableContainerReferenceId == globalScopeVariables.Id)
437437
{
438-
// Determine which stackframe's local scope the variable is in.
439-
StackFrameDetails[] stackFrames = await this.GetStackFramesAsync().ConfigureAwait(false);
440-
for (int i = 0; i < stackFrames.Length; i++)
441-
{
442-
var stackFrame = stackFrames[i];
443-
}
438+
scope = VariableContainerDetails.GlobalScopeName;
444439
}
445-
446-
if (scope == null)
440+
else
447441
{
448-
// Hmm, this would be unexpected. No scope means do not pass GO, do not collect $200.
442+
// Hmm, this would be unexpected. No scope means do not pass GO, do not collect $200.
449443
throw new Exception("Could not find the scope for this variable.");
450444
}
451445

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DebugEvaluateHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
using System;

0 commit comments

Comments
 (0)