Skip to content

Extension crashes when formating #2027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
happywino opened this issue Jun 17, 2019 · 9 comments
Open

Extension crashes when formating #2027

happywino opened this issue Jun 17, 2019 · 9 comments

Comments

@happywino
Copy link

Issue Description

Whenever I try to format code, either from the context menu or via Ctrl-K Ctrl-F, the extension crashes, even on a file only containing "Import-Module ActiveDirectory". The log contains an entry "Exception: PSScriptAnalyzer cannot be imported, AnalysisService will be disabled", should I be installing that or is it expected to be installed by the extension?

Attached Logs

EditorServices.log
vscode-powershell.log

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 6.3.9600
VSCode 1.35.1
PowerShell Extension Version 2019.5.0

PowerShell Information

Name Value
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 6.3.9600.19170
PSCompatibleVersions 1.0 2.0 3.0 4.0
PSRemotingProtocolVersion 2.2

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
gitlens eamodio 9.8.2
powershell ms-vscode 2019.5.0
@SydneyhSmith
Copy link
Collaborator

Can you report the output of the following in the Integrated Console:

  • Import-Module PSScriptAnalyzer -PassThru
  • gmo -list PSScriptAnalyzer
  • gci ~\.vscode\extensions\ms-vscode.powershell-2019.5.0\modules
  • $env:PSModulePath

@happywino
Copy link
Author

happywino commented Jun 18, 2019

PS C:\Users\ad_jcphilli> Import-Module PSScriptAnalyzer -PassThru
Import-Module : The specified module 'PSScriptAnalyzer' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ Import-Module PSScriptAnalyzer -PassThru
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (PSScriptAnalyzer:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
 
PS C:\Users\ad_jcphilli> gmo -list PSScriptAnalyzer
PS C:\Users\ad_jcphilli> gci ~\.vscode\extensions\ms-vscode.powershell-2019.5.0\modules


    Directory: C:\Users\ad_jcphilli\.vscode\extensions\ms-vscode.powershell-2019.5.0\modules


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         6/17/2019   9:32 AM            docs
d----         6/17/2019   9:32 AM            Plaster
d----         6/17/2019   9:32 AM            PowerShellEditorServices
d----         6/17/2019   9:32 AM            PowerShellEditorServices.VSCode
d----         6/17/2019   9:32 AM            PSScriptAnalyzer
-a---         6/17/2019   9:32 AM        370 README.md


PS C:\Users\ad_jcphilli> $env:PSModulePath
C:\Users\ad_jcphilli\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell\;C:\Program Files (x86)\Microsoft SQL Server\120\Tool
s\PowerShell\Modules\;C:\Program Files\Common Files\Skype for Business Server 2015\Modules\;C:\Users\ad_jcphilli\.vscode\extensions\ms-vscode.powershell-2019.5.0\modules
PS C:\Users\ad_jcphilli>

@rjmholt
Copy link
Contributor

rjmholt commented Jun 18, 2019

Hmmm that's odd; the shipped PSScriptAnalyzer seems to be there, and that directory is on the path, but it's not available for some reason.

Maybe try:

Import-Module C:\Users\ad_jcphilli\.vscode\extensions\ms-vscode.powershell-2019.5.0\modules\PSScriptAnalyzer -PassThru

And let us know what the output is

@happywino
Copy link
Author

PS C:\Users\ad_jcphilli> Import-Module C:\Users\ad_jcphilli.vscode\extensions\ms-vscode.powershell-2019.5.0\modules\PSScriptAnalyzer -PassThru
Import-Module : The specified module 'C:\Users\ad_jcphilli.vscode\extensions\ms-vscode.powershell-2019.5.0\modules\PSScriptAnalyzer' was not loaded because no valid module file was found in any module directory.
At line:1 char:1

  • Import-Module C:\Users\ad_jcphilli.vscode\extensions\ms-vscode.powershell-2019. ...
  •   + CategoryInfo          : ResourceUnavailable: (C:\Users\ad_jcp...SScriptAnalyzer:String) [Import-Module], FileNotFoundException
      + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
    
    

The contents of "C:\Users\ad_jcphilli.vscode\extensions\ms-vscode.powershell-2019.5.0\modules\PSScriptAnalyzer" is a single folder named "1.18.0", is that expected?

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Jun 20, 2019

is a single folder named "1.18.0", is that expected?

Yes. This is expected. This is the structure of how PowerShellGet installs modules:

...
/ModuleName/VersionNumber/MyModule.psd1
...

However... @rjmholt and I learned that support for this version number part didn't come until v5.0... and since you're on v4, it doesn't work.

We will need to restructure our build logic here to move the contents of the VersionNumber folder under the ModuleName folder. That way the new layout will look like:

...
ModuleName/ModuleName.psd1
...

If you have any interest in contributing to the project, this change would be pure PowerShell and pretty straightforward. Otherwise we will get to it as soon as we can!

@TylerLeonhardt
Copy link
Member

Just so I've written in down for myself, this change only needs to go in the legacy/1.x branch

@ghvanderweg
Copy link

I'd like to pick this one up :)

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Jun 20, 2019

Awesome! Let me know if anything is not clear.

I should note that this fix will require to you verify your fix on PowerShell v4 if you can...
Since this fix is for PowerShell v4 and v3 as well, you should work off of the legacy/1.x branch instead of the master branch.

When you clone both vscode-powershell and PowerShellEditorServices make sure you run:

git checkout legacy/1.x

in each folder to work off of that code.

Success here is: "I can format my scripts when using PowerShell v4 with the PowerShell extension."

@ghvanderweg
Copy link

Thanks for the clear instructions! Verifying on PowerShell v3 and v4 is not a problem, I can spin up VM's for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants