Skip to content

Commit 341c3fc

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

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)