Closed WillemToorenburgh closed 4 months ago
Oh, that is a very interesting story, and there's quite a bit to unpack here.
First thing, -NoProfile
is merged but the version with this is not yet released. I wonder if there's something in your profile that may be spoiling things for us. We'll see about that.
The whole endeavor I assume could be connected with #79, and, through that, to https://github.com/PowerShell/PowerShell/issues/11747 (a long-standing issue I recently fixed myself in PowerShell — the fixed version is also not yet released).
When you run pwsh.exe
via PowerShell, you are supposed to escape the $
sign, like this:
> pwsh.exe -Command "(`$PSVersionTable.PSVersion, `$PSVersionTable.PSEdition) -join ' '"
Otherwise, it will interpolate $PSVersionTable
and I guess nothing good will come from that. So, this part I understand.
But then, it is not yet clear what happens with the process output. Maybe stderr is blocked or something?
I digress and let's get to the point, though.
First of all, how do you install PowerShell?
Also, are you absolutely sure the plugin runs "C:\Program Files\PowerShell\7\pwsh.exe"
and not a binary from some other place, such as dotnet tool
or something else?
I think the screenshot is from Process Explorer, so, just as a sanity check, could you please show a full screenshot of the tooltip with the process command line?
Could you please run the following command from cmd
(important: from cmd
!)?
pwsh.exe -Command "($PSVersionTable.PSVersion, $PSVersionTable.PSEdition) -join ' '" > out.txt
And then show the output of this command (if there's any output whatsoever) and the contents of out.txt
?
The very presence of any output could hint us at what's going on.
Thanks for the response!
My bad, I should have been checking the code at the release tag 😅
choco install pwsh
in an elevated powershell.exe
promptcmd.exe
from a pwsh.exe
shell, which could have messed things up. Here's the run from cmd.exe
:
>pwsh.exe -Command "($PSVersionTable.PSVersion, $PSVersionTable.PSEdition) -join ' '" > out.txt
...which gave no output to the terminal. However, the out.txt
is very interesting:
[31;1mImport-Module: [0mC:\Users\willem.toorenburgh\Documents\PowerShell\profile.ps1:23[0m
[31;1m[0m[36;1mLine |[0m
[31;1m[0m[36;1m[36;1m 23 | [0m [36;1mImport-Module "C:\Program Files\PowerToys\WinUI3Apps\..\WinGetCommand[0m .[0m
[31;1m[0m[36;1m[36;1m[0m[36;1m[0m[36;1m | [31;1m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
[31;1m[0m[36;1m[36;1m[0m[36;1m[0m[36;1m[31;1m[31;1m[36;1m | [31;1mCould not load file or assembly 'PowerToys.CmdNotFound, Version=0.78.0.0, Culture=neutral, PublicKeyToken=null'.[0m
[31;1mSet-PSReadLineOption: [0mC:\Users\willem.toorenburgh\Documents\PowerShell\profile.ps1:49[0m
[31;1m[0m[36;1mLine |[0m
[31;1m[0m[36;1m[36;1m 49 | [0m [36;1mSet-PSReadLineOption -PredictionSource HistoryAndPlugin[0m
[31;1m[0m[36;1m[36;1m[0m[36;1m[0m[36;1m | [31;1m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
[31;1m[0m[36;1m[36;1m[0m[36;1m[0m[36;1m[31;1m[31;1m[36;1m | [31;1mThe predictive suggestion feature cannot be enabled because the console output doesn't support virtual terminal[0m
[31;1m[0m[36;1m[36;1m[0m[36;1m[0m[36;1m[31;1m[31;1m[36;1m[31;1m[36;1m | [31;1mprocessing or it's redirected.[0m
7.4.0 Core
Looks like your suspicion is right, it's my profile. The culprits are PowerToys CommandNotFound and Set-PSReadLineOption -PredictionSource HistoryAndPlugin
. Speaking of which, you can see exactly what I use, as I commit it to Github for portability: https://github.com/WillemToorenburgh/pwsh-profile/blob/main/profile.ps1
I put it into $PROFILE.CurrentUserAllHosts
as I don't want to have to duplicate my profile across >4 different shell hosts, and it seems like the pwsh.exe
spawned by Rider is included.
If I modify the command to be
pwsh.exe -NoProfile -NonInteractive -Command "($PSVersionTable.PSVersion, $PSVersionTable.PSEdition) -join ' '" > out.txt
then the output is as expected: 7.4.0 Core
.
Looks like your merged -NoProfile
is enough to be a fix! You could consider adding -NonInteractive
for extra safety, but I imagine -NoProfile
should be plenty. Thanks for the help!
Thanks for your response. -NonInteractive
is a good option as well, I'll add it.
Environment info
Powershell Plugin version: 2.6.0 JetBrains Rider version 2023.3.4 Powershell version: 7.4.1
Hey there!
The issue
The extension seems to fail to detect the version of Powershell 7 I'm using. The language server seemingly never starts up.
The details
I loaded up a Powershell script I'm authoring in Rider with your extension installed, and got some strange syntax highlighting:![image (2)](https://github.com/ant-druha/intellij-powershell/assets/50425141/665260b6-9812-4631-a5d6-d6426a3a7de2)
None of the inspections were working, either.
I thought this could be due to a Powershell version mismatch, so I checked the settings for the plugin. Strangely, the executable was the correct one, but the text below said it was version 5.1:![image (3)](https://github.com/ant-druha/intellij-powershell/assets/50425141/f30e8f6d-2cf7-43f0-9268-103d7f3e18e0)
When I tried changing the executable to
powershell.exe
the syntax highlighting and analysis worked correctly, though of course it stumbled on any Powershell 6+ features. I checked Process Explorer to see how Rider was executingpowershell.exe
, and saw it was correctly launching the editor services.At this point, I uninstalled and reinstalled the plugin, for good measure.
After changing the executable back to![image (4)](https://github.com/ant-druha/intellij-powershell/assets/50425141/35851fdf-5997-4269-9967-44c60ac29072)
pwsh.exe
, I checked the spawnedpwsh.exe
processes and saw a bunch of them:They all had this command line invocation:
It's looking like the plugin code is having trouble interpreting the output of the command. I first thought it could be a quoting/interpolation issue, as when I run the same command from within a
pwsh.exe
shell, it throws an error:Converting to single quotes on the outside and double quotes in the
-join
fixed this when I ran it inpwsh.exe
and I tried poking around in your source to see if I could make that change and test it locally. However, I've never developed anything in Kotlin before and know nothing of the ecosystem. The learning curve is sadly a bit too steep for me to just pick it up and go.However it's likely that's not the issue anyhow, as the command as originally formatted works fine when run through
cmd.exe
, and, I assume, through theGeneralCommandLine
method. I did notice that theGeneralCommandLine
arguments include-NoProfile
, while what's getting executed on my machine does not. Not sure what this means, honestly, seeing as I've got the latest version of the plugin installed.