-
Notifications
You must be signed in to change notification settings - Fork 236
CodeCompletion exposes cmdlets not available to the parent runspace #1281
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
Comments
@dkattan I'm curious where you saw that this is the behavior of tab completion in CLM... For me |
I think it’s worth noting that there is be a difference between ConstrainedLanguage mode and a Constrained Runspace. A constrained runspace essentially has no cmdlets except for the ones explicitly added. It’s created using InitialSessionState.Create() instead of InitialSessionState.CreateDefault() or CreateDefault2(). There seems to be no support for .Create(), there is however an environmental variable to use CreateDefault instead of CreateDefault2. That being said, I think it’s a reasonable expectation for PSES to not return information about cmdlets not available in the Constrained Runspace it was spawned from. |
It’s not so much about TabExpansion as much as that illustrates that the runspace PSES uses to provide code completion is in fact a completely different one than what it was spawned from.
I totally get that you guys’ primary use case revolves around the assumption that when VS Code loads, there is no expectation that the calling runspace has been customized in any way other than the system default. But I would expect that if I did take the time to customize the parent runspace to my liking, adding variables, cmdlets, modules, etc they are available for CodeCompletion and anything I explicitly exclude would not be available.
|
I began implementing a potential solution in #1282 I decided not to allow the end user to specify InitialSessionState as a separate parameter to Start-EditorServices, but instead infer it from Runspace.DefaultRunspace.InitialSessionState. Since InitialSessionState contains LanguageMode I simply replaced all the places @TylerLeonhardt was referencing LanguageMode and used the full InitialSessionState object instead. |
Closing due to no activity |
Summary
When calling PSES programmatically (from C# but using the supported script) in a ConstrainedRunspace in ConstrainedLanguage mode, information about all cmdlets and the underlying filesystem is exposed via CodeCompletion.
Steps to Reproduce
Expected Behavior
CodeCompletion should only return information about the specific set of modules I loaded into my runspace via InitialSessionState
What actually happens
All available modules are available via CodeCompletion and my custom (and likely unnecessary) TabExpansion2 function never gets called.
Possible Fixes
Instead of always creating a new runspace in PowerShellContext.Create() use the existing one.
PowerShellEditorServices/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs
Line 216 in d54bda7
Create a new runspace but allow the user to specify a custom initialsessionstate. Perhaps do this instead of the recent change that simply passes in LanguageMode as this would give the user more granular control of the runspace. This would naturally require Start-EditorServices to be modified to accept an initiationsessionstate object.
I feel pretty confident I can implement the required changes, I’d like some feedback as to which option is most feasible or if there are perhaps intentional reasons a new runspace is being created.
The text was updated successfully, but these errors were encountered: