Skip to content

IntelliSense in the editor causes modules to be loaded #715

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

Closed
pcgeek86 opened this issue May 6, 2017 · 9 comments · Fixed by PowerShell/PowerShellEditorServices#1484
Closed
Labels
Area-IntelliSense Bug: PowerShell Core Bugs when using PowerShell Core. Issue-Bug A bug to squash. Resolution-External Will close automatically.

Comments

@pcgeek86
Copy link
Contributor

pcgeek86 commented May 6, 2017

While I'm writing PowerShell code in Visual Studio Code on Mac, I notice that messages are randomly printed to the Integrated Terminal. Those messages typically indicate that a module is being imported, and sometimes my environment will change as a result (eg. posh-git changes my prompt) against my will.

While the rich Intellisense metadata is useful for development, we should investigate a method of providing this metadata while simultaneously preventing unwanted changes to the development environment. Ideas proposed by @daviwil and myself include:

  • Add a setting that prevents automatic import of modules (or perhaps opts into it)
  • Parse tooltips from CompletionResult objects, instead of importing module
  • Run metadata gathering in separate PowerShell Runspace or process

Cheers,
Trevor Sullivan

@rkeithhill
Copy link
Contributor

posh-git should not change the prompt function if it detects the prompt function is not the PowerShell default prompt i.e. the use has customized it. You could workaround the prompt changing issue by creating a custom prompt function in the Microsoft.VSCode_profile.ps1 file. Although, it would be better if posh-git were never imported as this module is meant for interactive use and isn't something you'd ever script against.

BTW you should be able to turn off module autoloading with:

$PSModuleAutoloadingPreference = 'None'

You could try putting that in the profile until a setting is added for it.

@pcgeek86
Copy link
Contributor Author

pcgeek86 commented May 7, 2017

Not a bad idea for a workaround, but I don't want to disable module auto-loading, as that would break virtually all of my code.

@daviwil
Copy link
Contributor

daviwil commented May 7, 2017

@lzybkr recommended using CommandInvocationIntrinsics.GetCommand instead of calling Get-Command directly, this approach won't cause the module to be loaded. I think I'll give that a shot first then try some other approaches if it doesn't work for our scenarios.

@daviwil daviwil changed the title Modules are randomly imported IntelliSense in the editor causes modules to be loaded May 7, 2017
@daviwil daviwil added this to the May 2017 milestone May 7, 2017
@pcgeek86
Copy link
Contributor Author

pcgeek86 commented May 7, 2017

Is that more or less the equivalent of using Reflection-only loading of .NET assemblies?

@lzybkr
Copy link

lzybkr commented May 7, 2017

I suppose, but we don't use reflection only loads of binary modules, so in that sense, definitely not.

daviwil added a commit to daviwil/PowerShellEditorServices that referenced this issue May 15, 2017
This change resolves PowerShell/vscode-powershell#715 by changing our
usage of Get-Command to CommandInvocationIntrinsics.GetCommand so that
gathering command information doesn't cause modules to be loaded.
@daviwil
Copy link
Contributor

daviwil commented May 15, 2017

Did some work on this but I think I want to polish it a bit more before I ship it.

@SydneyhSmith
Copy link
Collaborator

Marking this as resolved-external as this comes from PowerShell's tab completion experience.

@SydneyhSmith SydneyhSmith added the Resolution-External Will close automatically. label Mar 17, 2020
@MartinGC94
Copy link
Contributor

I'm sorry for commenting on such an old issue, I can open a new one if requested but I disagree with the conclusion here.

This is not a Powershell issue, if you open up ISE or a PS console with/without PSReadline it won't auto import modules when you invoke command completion. This only happens in VS code, specifically when you are hovering over a command in the intellisense menu.

It's pretty easy to demonstrate:

  • Open up a normal PS console and VS code
  • Check imported modules with Get-Module
  • Tab complete a command from an unimported module like Get-NetIPAddress
  • Check imported modules again with Get-Module
  • Note how only VS code will have imported the unwanted NetTCPIP module

I think the problem is that VS code runs some additional code when you are hovering over an item in the intellisense menu to display command help. Powershell already provides the parameter sets as a tooltip if a module has been imported so the only thing VS code adds is the short synopsis for what the command does.
This feature needs to either be removed or made smarter so it only shows that help info if the module has already been imported, otherwise I don't see how intellisense is ever going to feel good in VS code for Powershell.

@andyleejordan
Copy link
Member

That seems reasonable @MartinGC94, I'll reopen this so you can close it again with your PR.

@andyleejordan andyleejordan reopened this May 24, 2021
andyleejordan pushed a commit to PowerShell/PowerShellEditorServices that referenced this issue May 24, 2021
Fixes PowerShell/vscode-powershell#715 by not getting command
documentation unless the module has already been imported.
@andyleejordan andyleejordan removed the Needs: Maintainer Attention Maintainer attention needed! label Jun 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IntelliSense Bug: PowerShell Core Bugs when using PowerShell Core. Issue-Bug A bug to squash. Resolution-External Will close automatically.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants