-
Notifications
You must be signed in to change notification settings - Fork 235
Add support for loading host profile scripts #199
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
Conversation
@@ -7,6 +7,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server | |||
{ | |||
public class LanguageServerSettings | |||
{ | |||
public bool LoadProfiles { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the right setting name for what the user would specify in VS Code? I used the positive form rather than the negative form (noProfile
) since profile loading is never performed by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me especially if we need a positive form of the setting.
This PR isn't fully done yet, I still need to do a little cleanup, commenting, and name tweaking. Would appreciate some feedback on the design to make sure I didn't miss anything. I should be replicating the behavior of |
Just curious, why differ by not loading profiles by default? Every PowerShell editor since 2006 has loaded profiles by default, just as PowerShell does. |
I suppose the main concern is that if profiles are all of a sudden being loaded in VS Code by default, it could break existing users (maybe they do something that we don't support yet). When used as an API for other purposes, I'd expect Editor Services to only load profiles when asked for. I can see your point though, there's already the established concept of Keith, what do you think? Should we load profiles for the language server by default? |
Just tweeted a question about this to get some more feedback. |
If a profile contains things that are not host-specific and yet are not supported in your editor, those things can be moved into an if statement that checks the host name. People using VS Code while PowerShell-support is still a work in progress should be technical enough to manage the transition through the process. |
I'm OK with that as long as there is a way to turn it off like ISE's I can update some of my profile.ps1 files to make this work for me. Some I have updated to only load PSReadline in the "ConsoleHost" but I have some other machines I need to make that change on. |
Ok, after getting some good feedback on Twitter, here's what I think I'll do. In the beginning I'll have the Regardless of whether it's on or off by default, I think I like the strategy of having boolean parameters mean 'true' for the positive case rather than the negative case so there's no cognitive dissonance. However, I like |
One other thing I realized is that I'll also need to set |
I think that host name is fine. Just make sure the profile filename does not have spaces in it. For that host name, I'd expect a profile name like If you wanted to shorten the |
Technically |
This approach makes sense to me. My suggestion was thinking more about when you have a REPL anyway. |
👍 |
Awesome, thanks for all the ideas and help! |
This change adds support for loading both host-agnostic and host-specific profile scripts for the current user and all users depending on which of those scripts are available on the system. Profile loading behavior is opt-in and not enabled by default. Regardless of whether profiles get loaded, a $profile variable is inserted into the PowerShellContext's runspace upon initialization. Resolves #111.
9d56268
to
5a3d905
Compare
Alright, I think the quality on this is pretty good now. One last-minute change I made was to allow the "host application" (the editor) to pass their version through so that it shows up in The new extensibility model will introduce a How does that sound? |
Glad you're setting up the version the right way as well. Some editors in the past have simply reported the PS version in that property, but modules that extend the editor will need the editor version. |
Thanks! Glad to hear that was the right thing to do. If you can think of anything else that would be the "right way" compared to other PowerShell hosts, definitely let me know. |
This change adds support for loading both host-agnostic and host-specific
profile scripts for the current user and all users depending on which of
those scripts are available on the system. Profile loading behavior is
opt-in and not enabled by default. Regardless of whether profiles get
loaded, a $profile variable is inserted into the PowerShellContext's
runspace upon initialization.
Resolves #111.
This change is