PowerShell / PowerShell/vscode-powershell
IScriptExtent.File Property is null in VS Code
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.9k
- Forks
- 547
- PR merge metrics
- No merged PRs in 30d
Description
When attempting to write a custom PSScriptAnalyzer rule, the IScriptExtent.File property is null in the Problems pane of VS Code, but is not null not outside of the VS Code Problems pane.
Steps to reproduce
git clone https://github.com/bergmeister/PSScriptAnalyzer-VSCodeIntegration.git
(Get-Content .\PSScriptAnalyzer-VSCodeIntegration\CustomPSScriptAnalyzerRules.psm1) -replace 'Message\s+=.+$', 'Message = "`$ast.Extent.File = $($ast.Extent.File)"' | Set-Content .\PSScriptAnalyzer-VSCodeIntegration\CustomPSScriptAnalyzerRules.psm1
Set-Location PSScriptAnalyzer-VSCodeIntegration
Invoke-ScriptAnalyzer -Path .\scriptWithViolations.ps1 -CustomRulePath .\CustomPSScriptAnalyzerRules.psm1 -IncludeRule Warning*
code .
In VS Code, open scriptWithViolations.ps1, then open the Problems pane (Ctrl + Shift + M).
Expected behavior
$ast.Extent.File is populated with the absolute path of the script file scriptWithViolations.ps1, the same as the output from Invoke-ScriptAnalyzer
Actual behavior
Invoke-ScriptAnalyzer returns:
PS C:\Users\<redacted>\PSScriptAnalyzer-VSCodeIntegration> Invoke-ScriptAnalyzer -Path .\scriptWithViolations.ps1 -CustomRulePath .\CustomPSScriptAnalyzerRules.psm1 -IncludeRule WarningAboutDoSomething
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
CustomPSScriptAnalyzerRules\Warning Warning scriptWith 1 $ast.Extent.File = C:\Users\<redacted>\PSScriptAnaly
AboutDoSomething Violations zer-VSCodeIntegration\scriptWithViolations.ps1
.ps1
CustomPSScriptAnalyzerRules\Warning Warning scriptWith 1 $ast.Extent.File = C:\Users\<redacted>\PSScriptAnaly
AboutDoSomething Violations zer-VSCodeIntegration\scriptWithViolations.ps1
.ps1
while VS Code's Problems pane shows $ast.Extent.File as $null
$ast.Extent.File =
If an unexpected error was thrown, then please report the full error details using e.g. $error[0] | Select-Object *
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 7.4.5
PSEdition Core
GitCommitId 7.4.5
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.22.0
1.22.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with CustomPSScriptAnalyzerRules.psm1 and scriptWithViolations.ps1 from the PSScriptAnalyzer-VSCodeIntegration repository, comparing Invoke-ScriptAnalyzer output with the VS Code Problems pane. Start at the extension's diagnostic handling and trace how the script extent reaches Problems; done means $ast.Extent.File is populated there with the script's absolute path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell, vscode
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100