Support syntax-highlighting and verifying/linting inline PowerShell scripts
rklec opened this issue · 4 comments
Use case / Problem
I use this extension here to lint, check and write Azure Pipelines YAML files, which are CI configuration files.
Now there are often some inline PowerShell scripts and they are just shown as a big block of text and no help like syntax highlighting or even linting, code snippets, IntelliSense or so is provided.
An example:
- task: PowerShell@2
displayName: 'Do something...'
inputs:
targetType: 'inline'
script: |
# ...
Proposed solution
It would be great if you could integrate with Microsoft's official PowerShell VSCode extension, so you use their features in your inline PowerShell parts.
IMHO it is fine to require to install both extensions, if one wants to use that feature.
To do so, I have also created a corresponding issue on their repo: PowerShell/vscode-powershell#4017
Workaround / Alternative solutions
I know I could switch to external PowerShell scripts as it's own .ps1
files, but these also complicate the Azure Pipelines a lot, given that I know also need to clone the correct repository (if you have multiple repositories) and (always) provide the correct path.
In complex scenarios it thus would be great to just keep using inline PowerShell scripts, but have the full power of the PS extension linting and syntax highlighting.
@rklec Thanks for reporting! We are working on more prioritized issues now but will get back to this one soon
I definitely would love this as a feature. I'm curious to see what happens when the pipeline syntax is mixed inline with powershell. I'm assuming arguments is the correct way but this is still convenient sometimes.
e.g:
Valid in pipeline
- pwsh: Write-Host ${{variables.applicationName}}
Not valid in powershell
Write-Host ${{variables.applicationName}}
// ERR: Use `{ instead of { in variable names.
// ERR: Unexpected token '}' in expression or statement.
Yeah that's a problem, but likely not such a bug thing if it is just about syntax highlighting. You can worka round it by passing all input variables via env:
first and then read it in the PS script via $env
.
Alternatively, it would need some special handling/support for that syntax here, of course.
But the PowerShell people at PowerShell/vscode-powershell#4017 (comment) said that syntax highlighting would be the first step and quite easy as it seems (keyword "grammar injection"), so one should probably first focus on that.
I've looked into this briefly, in the past. Grammar injection does make this easy, but the bigger problem is that the YAML grammar that we use doesn't currently have an easy way to only inject the PowerShell grammar into pwsh
/powershell
tasks. And it'll be even harder for verbose-style task: PowerShell@2
tasks. That said - this is something I want to get done, eventually. Just can't give any time estimates or commitments.
I'm also going to close this as a duplicate of #103 to keep the issues consolidated.