|
1 | | -// Copyright (c) Microsoft Corporation. |
| 1 | +// Copyright (c) Microsoft Corporation. |
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | 4 | using System; |
@@ -394,25 +394,21 @@ public async Task<string> SetVariableAsync(int variableContainerReferenceId, str |
394 | 394 | } |
395 | 395 |
|
396 | 396 | 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) |
404 | 405 | { |
405 | 406 | scope = VariableContainerDetails.ScriptScopeName; |
406 | 407 | } |
407 | 408 | else if (variableContainerReferenceId == globalScopeVariables.Id) |
408 | 409 | { |
409 | 410 | scope = VariableContainerDetails.GlobalScopeName; |
410 | 411 | } |
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 | | - } |
416 | 412 |
|
417 | 413 | // Now that we have the scope, get the associated PSVariable object for the variable to be set. |
418 | 414 | var getVariableCommand = new PSCommand() |
|
0 commit comments