Skip to content

Commit 06af249

Browse files
committed
Fix scope guessing logic in SetVariableAsync
1 parent cc71a7e commit 06af249

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

+8-7
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,14 @@ public async Task<string> SetVariableAsync(int variableContainerReferenceId, str
400400
}
401401

402402
VariableDetailsBase variable = variableContainer.Children[name];
403-
// Determine scope in which the variable lives so we can pass it to `Get-Variable -Scope`.
404-
string scope = null; // TODO: Can this use a fancy pattern matcher?
403+
404+
// Determine scope in which the variable lives so we can pass it to `Get-Variable
405+
// -Scope`. The default is scope 0 which is safe because if a user is able to see a
406+
// variable in the debugger and so change it through this interface, it's either in the
407+
// top-most scope or in one of the following named scopes. The default scope is most
408+
// likely in the case of changing from the "auto variables" container.
409+
string scope = "0";
410+
// NOTE: This can't use a switch because the IDs aren't constant.
405411
if (variableContainerReferenceId == localScopeVariables.Id)
406412
{
407413
scope = VariableContainerDetails.LocalScopeName;
@@ -414,11 +420,6 @@ public async Task<string> SetVariableAsync(int variableContainerReferenceId, str
414420
{
415421
scope = VariableContainerDetails.GlobalScopeName;
416422
}
417-
else
418-
{
419-
// Hmm, this would be unexpected. No scope means do not pass GO, do not collect $200.
420-
throw new Exception("Could not find the scope for this variable.");
421-
}
422423

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

0 commit comments

Comments
 (0)