Commit 387d843
Resolve
When a watch or `evaluate` request resolved a naked variable reference,
`GetVariableFromExpression` searched the flat `variables` list, which is
populated broadest-to-narrowest (global, then script, then local, then
stack frames). `FirstOrDefault` therefore returned the global/parent-scope
copy of a variable whenever the same name also existed in a more local
scope, even though the Variables explorer and PowerShell itself show the
local value.
We now search the local, script, and global scope containers in that order
first, falling back to the full flat list so names that only live in a
frame still resolve. This matches PowerShell's own variable resolution
semantics. Added a regression test (and `VariableScopeTest.ps1`) that
shadows a variable across scopes and asserts the local value wins.
Fixes #1882.
Drafted by Copilot (Claude Opus 4.8).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>evaluate/watch variables from the most-local scope1 parent 6ad4f46 commit 387d843
3 files changed
Lines changed: 36 additions & 1 deletion
File tree
- src/PowerShellEditorServices/Services/DebugAdapter
- test
- PowerShellEditorServices.Test/Debugging
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
311 | | - | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
312 | 321 | | |
313 | 322 | | |
314 | 323 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
644 | 644 | | |
645 | 645 | | |
646 | 646 | | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
647 | 668 | | |
648 | 669 | | |
649 | 670 | | |
| |||
0 commit comments