PowerShell / PowerShell/vscode-powershell
Variable in Watch pane expression is not evaluated in the current function's scope
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 1.9k
- Fork
- 548
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo il problema con lo script PowerShell nella sezione Steps to Reproduce, interrompendo l'esecuzione all'interno di Foo dopo l'assegnazione di $scope. Traccia la valutazione dell'espressione Watch del debugger dell'estensione e confrontala con il riquadro Variables e la valutazione di Terminal. Il lavoro è completato quando il riquadro Watch risolve lo scope della funzione corrente e mostra "Foo" invece del valore del parent "script".
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- powershell, typescript, vscode
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100