-
Notifications
You must be signed in to change notification settings - Fork 512
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
IntelliSense in the editor causes modules to be loaded #715
Comments
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. |
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. |
@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. |
Is that more or less the equivalent of using Reflection-only loading of .NET assemblies? |
I suppose, but we don't use reflection only loads of binary modules, so in that sense, definitely not. |
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.
Did some work on this but I think I want to polish it a bit more before I ship it. |
Marking this as resolved-external as this comes from PowerShell's tab completion experience. |
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:
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. |
That seems reasonable @MartinGC94, I'll reopen this so you can close it again with your PR. |
Fixes PowerShell/vscode-powershell#715 by not getting command documentation unless the module has already been imported.
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:
CompletionResult
objects, instead of importing moduleCheers,
Trevor Sullivan
The text was updated successfully, but these errors were encountered: