vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

$env:PSModulePath Question / Potential Issue

Open GHRoss opened this issue 7 years ago • 7 comments

I'm having an issue with Intellisense being very slow.

I've managed to whittle it down to VS Code loading modules over the network, so every time I hit tab, it goes off to the network share and does what it needs to do and then Intellisense works.

This can be up to 2 minutes at a time, however.

I removed the entry from $env:PSModulePath in the integrated VS Code terminal, fine, Intellisense is once again rapid and I can continue happily with my work, then around 30 seconds or so later, everything slows down again.

Lo and behold, the UNC of the file share is back in $env:PSModulePath! I've tested this in the ISE and do not get the same issue after removing the UNC share path.

Happy to submit logs if required, hoping there's just something I'm missing, however.

EDIT: It seems to be that when I hit tab or Intellisense trys to fire, it adds the UNC share path back to my $env:PSModulePath. Again tried with the ISE and don't get the same thing, so I believe this to be a bug.

SECOND EDIT: It appears to add the path back into $env:PSModulePath as soon as you click into the editor window.

GHRoss avatar Apr 11 '18 23:04 GHRoss

fascinating... sounds like a bug... Thanks for the report! Where does it get the file share path from? Are you adding that to the PSModulePath in your profile or something?

It'd be helpful if you could share the logs.

TylerLeonhardt avatar Apr 12 '18 01:04 TylerLeonhardt

@tylerl0706 I'm not sure where it gets the file share path from.

I took everything out of my profile to eliminate that as an issue.

I don't like to assume, but I think as we have our documents redirected, it's using that location instead of the normal C:\Users\User.Name\WindowsPowerShell\Modules location.

I've moved all of the modules in there to C:\Program Files\WindowsPowerShell\Modules, and the speed is back to normal.

GHRoss avatar Apr 12 '18 14:04 GHRoss

Glad to see you're at least unblocked. Seems like a bug. We'll take a look.

TylerLeonhardt avatar Apr 17 '18 21:04 TylerLeonhardt

This is becoming a pain for me too. I have a number of module paths being inserted via my profile, and they seem to be overwritten whenever the script analyzer starts up. It's a piece of cake to replicate - is there anything I can provide to help with this?

Cirzen avatar Jan 02 '19 13:01 Cirzen

Any updates?

ajklotz avatar Dec 31 '19 15:12 ajklotz

This is caused by an underlying issue within PowerShell: https://github.com/PowerShell/PowerShell/issues/9921. I had hoped it would be fixed in PS 7, but unfortunately PS 7 still mutates the module path when new runspaces are opened.

Some approaches we can try:

  • Save and re-set the module path around PSSA invocations
  • Work with PSSA to allow runspace pools to be provided or disabled

rjmholt avatar Jan 02 '20 22:01 rjmholt

This seems to still be a problem? VSCode v1.92.2, extension v2024.2.2, PowerShell v7.4.5.

In my profile I change the order of PSModulePath in process context. It works great in standalone PowerShell consoles, in Windows Terminal, and I've verified with output that the profile runs successfully when VSCode and the extension starts up.

But right after when I write $env:PSModulePath.Split(';') in the integrated terminal using "PowerShell Extension", the PSModulePath in process context has been reset to default.

Related issues:

  • 2017-12-09 #1122
  • 2019-06-04 #2008
  • 2019-08-08 #2127

This causes conflicting assemblies when trying to load a PowerShell module thats also included with PowerShell, like Microsoft.PowerShell.PSResourceGet. Related issues:

o-l-a-v avatar Aug 29 '24 13:08 o-l-a-v