Skip to content

Commit a3e5e09

Browse files
committed
WIP: Fixed variable scope for set var
1 parent ff0c433 commit a3e5e09

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

+9-13
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;
@@ -394,25 +394,21 @@ public async Task<string> SetVariableAsync(int variableContainerReferenceId, str
394394
}
395395

396396
VariableDetailsBase variable = variableContainer.Children[name];
397-
// Determine scope in which the variable lives so we can pass it to `Get-Variable -Scope`.
398-
string scope = null; // TODO: Can this use a fancy pattern matcher?
399-
if (variableContainerReferenceId == localScopeVariables.Id)
400-
{
401-
scope = VariableContainerDetails.LocalScopeName;
402-
}
403-
else if (variableContainerReferenceId == scriptScopeVariables.Id)
397+
// Determine scope in which the variable lives so we can pass it to `Get-Variable
398+
// -Scope`. First we assume that it's in the local scope (which is most likely the
399+
// case), and then check if it is instead in the script or global scopes. There may be a
400+
// scenario where it's in none of these scopes, in which case things aren't going to
401+
// work, but since we can't tie scopes to stack frames, we just have to guess.
402+
string scope = VariableContainerDetails.LocalScopeName;
403+
// TODO: Can this use a fancy pattern matcher?
404+
if (variableContainerReferenceId == scriptScopeVariables.Id)
404405
{
405406
scope = VariableContainerDetails.ScriptScopeName;
406407
}
407408
else if (variableContainerReferenceId == globalScopeVariables.Id)
408409
{
409410
scope = VariableContainerDetails.GlobalScopeName;
410411
}
411-
else
412-
{
413-
// Hmm, this would be unexpected. No scope means do not pass GO, do not collect $200.
414-
throw new Exception("Could not find the scope for this variable.");
415-
}
416412

417413
// Now that we have the scope, get the associated PSVariable object for the variable to be set.
418414
var getVariableCommand = new PSCommand()

0 commit comments

Comments
 (0)