-
Notifications
You must be signed in to change notification settings - Fork 511
Add support for workspace profiles #190
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
After thinking about this a bit, it seems like the most obvious way to approach this is to define the concept of a "workspace profile" that gets loaded in addition to the VS Code host profiles. When the user loads a folder in VS Code, we'll look for a file called This will be useful when a project has certain modules it needs to load when the user loads up the project. This could also be useful to other editors so I won't be making it editor-specific (not placing the profile in the Thoughts? @rkeithhill |
I really like that idea. Would make development of modules and such much easier especially if I need to override installed modules with development versions. |
I like the idea. Do you want to load that file by a "conventional" name like |
If it is going to be editor agnostic, it would make sense to continue the pattern to have a generic Workspace profile and a Host/Editor specific profile that can be used. WorkspaceAllHosts : {WorkspaceRoot}\Workspace.profile.ps1
WorkspaceCurrentHost : {WorkspaceRoot}\Workspace.VSCode_profile.ps1 WorkspaceAllHosts would work well to cover the module loading scenarios since most of them shouldn't care about the Host to run. WorkspaceCurrentHost would cover the $psEditor commands that might be specific to an Editor that you wouldn't want to load up in another one. |
Like the idea, but not sure about using a generic file name like profile.ps1. I can imagine someone loading a project with a file named that and inadvertently running some code they didn't intend to. A safer way would be to include this in the .vscode folder, but i know you plan to leave this open for other editors. What if we had a project-level setting in there that would contain the path to the project profile script? That way you could choose to store it in the workspace root or any where else, and name it whatever you like. |
@dragonwolf83 Considering that this setting would only be in VSCode I don't think you would need multiple values. For Example in Sublime Text you would need something to be stored in their project file. |
I can see @mattmcnabb point. My PowerShell profile is a project so if I were using that workspace it would run every time. Let me offer a suggestion of the default profile to be By default the workspace profile would be |
Maybe this frickin' Linux stuff is starting to rub off on me but I'm strangely attracted to |
@rkeithhill The @PowerSchill I don't see why it wouldn't work in Sublime Text if there is an Integrated Terminal with PowerShell Editor Services. The As long as For example, I can see this being very useful in Visual Studio where I have scripts that automate Visual Studio in COM. I can open my project and have it run the PowerShell extension to run those commands or load a module that makes it easier to run those commands. @mattmcnabb if you referring to my post on name @Jaykul is any of this useful in what you did with Jupyter? I think your feedback would be good on this. |
I'm just saying that if there's a chance that a user will update the extension and then open a workspace that contains a file matching whatever the naming convention may be, then there is a risk and this should be avoided. Any code that is automtically run at load should be explicitly agreed to by the user. If the path to this file is set by a setting in the .vscode/settings.json and the setting is off by default, then the user should be protected against inadvertently launching a script. |
Given that the existing host-specific profiles already use |
Definitely love this idea. For security reasons would it be possible to have a prompt once per workspace? Similar to how VSCode handles workspace terminal customizations. As for the file name, I'd like to throw |
The main reason why I suggested Regarding whether we'd have a separate "all editors" profile, I think I'd prefer to keep things simple and not require a project to have multiple files for all the possible editors that developers in the project might want to use. I think it'd be better if the profile script could modify it's behavior based on the editor it gets loaded in. The goal of PS Editor Services is to minimize the need for editor-specific behavior, so I think we've failed if it's absolutely necessary to have separate profiles per editor. I'm also inclined to not allow this to be configured (at least at first). PowerShell doesn't let you customize it's profile paths :) The route I'd opt for is to have a standard naming convention so that you never have to look at the project's settings (across multiple editors...) to figure out what the workspace profile script is. I'd prefer to establish a standard name based on user feedback and then stick with that. |
Forgot to mention the security aspect: I can definitely show an initial prompt to ask the user whether they want to load the workspace profile for this project. |
I would prefer the Just my 2 cents worth... 😊 |
@gwojan that's actually part of my problem with that name. Do we really want this file to be hidden? I feel like it would be one of the first files you want to look at when opening someone else's project for the first time. Especially if it is registering editor commands. |
To be honest as long as its a preference I don't really care as much since I can set it to what I want. But for the general public it is a bigger deal. I do kind of like the With that said I am comfortable with any of the options stated. |
Thanks for all the feedback! I think at first I'll go with |
Sounds good. And if we need to add the setting, we can use |
Not sure if this issue needs reviving or not, but I would really appreciate this feature. I'm thinking primarily on folders that correspond with a repository. I don't really care about the filename nor the location of the file, but the .vscode folder looks like an obvious choice when implemented for VSC only. For VSC an enable/disable flag in the workspace settings would be a requirement for me. |
Just wanted to chime in with what might be considered a novel workaround — since the PowerShell Integrated Console for a workspace always starts up with the workspace root as the working directory, you can add code to your For example, you could do something like |
It looks like we just need to prepend In my opinion, adding an extension setting pointing to the profile is much preferred than a "magic" solution, as this feature would then be implicitly documented with the rest of the extension settings and subsequently much more discoverable. |
Not exactly, the idea is that it would be a profile per workspace similar to VSCode's
I don't see any problem with that. There could be a workspace overridable setting that specifies a profile path, though I would prefer a sensible default value as the "magic" option. |
What if we break up the implementation into the two steps below to start unblocking and gaining traction?
|
I'm not really sure what problem that's solving to be honest. That makes them too individualized for what I'm picturing (imo). Also you could set this up currently in your # $psEditor.Workspace.Path currently gives a malformed path in the
# preview version of the extension, but should be fixed next release.
$workspaceProfile = Join-Path $psEditor.Workspace.Path -ChildPath MyProfileName.ps1
if (Test-Path -LiteralPath $workspaceProfile) {
. $workspaceProfile
} If a feature is introduced to vscode-powershell that extends that functionality, I would personally prefer that it be more generalized.
That's more or less what I mean by option 2 in my post above. The setting to override it is the easy part, the harder (but probably still not too hard) part is setting up the prompt (particularly with the |
Right now there is no way to make linting work with custom modules, as you can in other language extensions. All I want is to make linting work automatically for repo contributors--defining a profile path in settings.json that gets checked in seems like a perfect candidate for this, as well as add the internal hook for adding more complex scenarios in the future. My point is that these steps aren't mutually exclusive and breaking down the problem into smaller pieces will increase the likelihood of gaining traction towards implementing all the pieces. If someone from the vscode-powershell team can confirm that this would be implemented by dot-sourcing the correct path in |
Would that be a workspace level setting or a user level setting? If the former, then that would still require the safe guards be in place. If the latter, then it's not automatic and (imo) doesn't provide significant value over having the above sample in your profile.
Yes and no. We have historically had a lot of half implemented features that never really went anywhere. I absolutely agree that this can be a fantastic feature, but I think there are some key parts to this feature that can't be skipped.
Unfortunately that won't work. When the start up script is ran it creates a new runspace, this is how we are able to implement our own The actual invocation would need to be done from PowerShellEditorServices (the language server vscode-powershell uses). Here is where the profiles are executed. Though you may need to alter ProfilePathInfo since it is currently hard coded to the same four options as You can also implement the prompt from there potentially, but I can't remember if the LSP will be busy while the console is initializing. If it's not busy, you can send a As long as there is a prompt, and a sensible default file name (preferably |
I found myself needing this type of functionality. Also providing a nudge, almost, exactly 1 year from @SydneyhSmith nudge :). |
I'm not an expert at this by any stretch of the imagination, but would a half-measure be a way to specify the While that doesn't quite get 100% there, it's one setup step to put the appropriate Again, I don't know if that would work and I don't know nearly enough about the extension or PSES. I don't know if the dots I'm seeing connect into a picture or a mess, thus why I'm just leaving this here for more experienced minds to ponder. |
It would not be appropriate to put this in User as the point is to have a custom profile for the workspace/project you are working on. As far as security goes, I don't think this should be a consideration. VSC already has a mechanism for trusting the files in a workspace/folder, so you either trust them or you don't. Anything more should fall to the developer. If people really feel this is necessary, a simple workspace setting checkbox for loading profile scripts or not should be sufficient. |
It'd be nice if we provided a way for the user to configure a startup script which gets run when VS Code opens their project folder. This would allow them to configure their session for the project they're developing without having to add anything extra to their profile. This would also allow registration of project-specific editor commands using the $psEditor API.
The text was updated successfully, but these errors were encountered: