PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.69k stars 479 forks source link

Suppress platform-specific parse errors #301

Open JasonMorgan opened 7 years ago

JasonMorgan commented 7 years ago

Please fill in these details so that we can help you!

System Details

Name                           Value
----                           -----
PSVersion                      6.0.0-alpha
PSEdition                      Core
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   3.0.0.0
GitCommitId                    v6.0.0-alpha.9
CLRVersion
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

workflow statements present an error and I can't seem to suppress it. I understand workflow won't run but I want to author them without an error. It'd be nice if I had the option to suppress or ignore it.

mrvladis commented 6 years ago

Have the same issue ;(

mmclane commented 6 years ago

Me too

rjmholt commented 6 years ago

Hi @JasonMorgan, @mrvladis, @mmclane would you be able to provide an example of:

The difficulty I see here is that not only will a workflow not run in PowerShell Core 6, but it won't even parse (i.e. PowerShell Core 6 itself will refuse to parse any input with a workflow in it). Since the extension relies on PowerShell to parse and provide completions for scripts, enabling workflows may involve disabling a good deal of extension functionality.

mmclane commented 6 years ago

I haven't done a lot with workflows but in working with Azure Automation I find myself needing to work with them. Not that I will be running them on my local machine. Instead I am writing a template that terraform renders into a working script. I change the langues from Plain Text to Powershell so that I can get the syntax highlighting and what not, but its all marked as red because of the workflow statements.

It doesn't matter what the script is, as soon as I wrap it in a workflow statement I get a problem and everything in that statement is marked as red.

image

What would be better is if it marked the workflow statement as red but not everything inside it. What would be better still is if I could mark that problem to be ignored. What I could live with is knowing how to disable [PowerShell] problems from being evaluated on that file.

Make sense?

mmclane commented 6 years ago

I am using Code version 1.25.1 PowerShell extension version 1.8.1

Name Value


PSVersion 6.0.2 PSEdition Core GitCommitId v6.0.2 OS Darwin 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 Platform Unix PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0

rkeithhill commented 6 years ago

You can switch to a "Windows PowerShell" session if you're on Windows or disable code analysis since it is PSScriptAnalyzer that generates that (parse) error e.g.:

07-19 08:44:39 2> Invoke-ScriptAnalyzer .\workflow.ps1
Invoke-ScriptAnalyzer : Parse error in file C:\Users\Keith\workflow.ps1:  Workflow is not supported in PowerShell Core at line 1 column 1.

Open up your user or workspace settings and add this setting:

"powershell.scriptAnalysis.enable": false

Short of disabling script analysis, there is nothing this extension can do. There is not even a PSSA rule we can ignore since it is a "parse" error. I suggest filing an issue with PSSA https://github.com/powershell/scriptanalyzer.

rjmholt commented 6 years ago

Ah cool! Yeah, I saw you're on macOS, and it does make sense that you might want to develop for scenarios off-platform.

Like @rkeithhill says, disabling analysis is the best workaround for now. Another thing worth noting is that there is an (old) issue open for turning parse errors into something more ignorable: https://github.com/PowerShell/PSScriptAnalyzer/issues/264. I know I've discussed this with @JamesWTruher as well.

yadirhb commented 2 years ago

Is there a workaround this yet?