PowerShell / PowerShell/vscode-powershell
Variable in Watch pane expression is not evaluated in the current function's scope
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 1.9k
- Forks
- 548
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Prerequisites
- I have written a descriptive issue title.
- I have searched all open and closed issues to ensure it has not already been reported.
- I have read the troubleshooting guide.
- I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
- I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
- If this is a security issue, I have read the security issue reporting guidance.
Summary
When the debugger breaks inside a function which sets a new value for a variable that was already set in the parent scope, a Watch pane expression monitoring that variable shows the value from the parent scope instead of the value from the current, function scope.
This behavior was previously reported in #1219.
PowerShell Version
PS C:\Code> $PSVersionTable; $Host
Name Value
---- -----
PSVersion 7.4.3
PSEdition Core
GitCommitId 7.4.3
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Name : Visual Studio Code Host
Version : 2024.2.2
InstanceId : 7faeaf28-aa27-43ff-9c1f-0ad26934f3ee
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
Visual Studio Code Version
1.91.0
ea1445cc7016315d0f5728f8e8b12a45dc0a7286
x64
Extension Version
ms-vscode.powershell@2024.2.2
Steps to Reproduce
Consider the following script that sets and outputs the value of a $scope variable before, inside, and after a function call:
function Write-Scope
{
Write-Host -Object "$`scope: $scope"
}
function Foo
{
Write-Scope
$scope = 'Foo'
Write-Scope
}
$scope = 'script'
Write-Scope
Foo
Write-Scope
The script writes the following text to the console:
$scope: script $scope: script $scope: Foo $scope: script
As seen in the attached screenshot, when the debugger breaks after a new value is assigned to $scope inside the Foo function, the expression $scope in the Watch pane still evaluates to the value from the parent scope ("script"). The expected value for $scope ("Foo") is displayed in the following locations:
- Inside the Local variable group of the Variables pane.
- After hovering the cursor over the
$scopetoken in the code editor. - After evaluating the expression
$scopein the Terminal.
Visuals
Logs
No response
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie damit, das Problem mit dem PowerShell-Skript im Abschnitt Steps to Reproduce zu reproduzieren, und halten Sie innerhalb von Foo an, nachdem $scope zugewiesen wurde. Verfolgen Sie die Auswertung des Watch-Ausdrucks des Debuggers der Erweiterung und vergleichen Sie sie mit dem Variablenbereich und der Terminal-Auswertung. Als erledigt gilt die Aufgabe, wenn der Watch-Bereich den aktuellen Funktions-Scope auflöst und "Foo" statt des übergeordneten Werts "script" anzeigt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- powershell, typescript, vscode
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100