DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Aaron Powell for Microsoft Azure

Posted on • Originally published at aaron-powell.com on

VS Code Profile Switcher Extensions Support

I've just released some updates to my VS Code Profile Switcher extension which adds the feature that was most required when I first announced it, extension support!

Extension Support

When creating a profile you might want to have different extensions loaded, say you're doing some React work, maybe you don't want the Vue extensions loaded, the more extensions you have installed, the more that VS Code has to activate, all of which takes time.

Now when you save a profile (either new or overriding an existing) the extension will look at all the extensions that you have and add them to your extensions profile. Then when you next load that profile the extension will look at what extensions are loaded in VS Code, compare that to the list of extensions that the profile says you should have, and installs the missing ones while removing the excess ones.

This is slightly different to the way settings are handled, settings are addative , meaning that any settings a profile has will be merged over the top of existing settings, but this didn't seem right for extensions.

Performance Considerations

I'll often flick between a number of profiles so I wanted to ensure that it performs decently. To this end when a profile removes an extension it moves it to globalStorage and then when it's needed again it'll copy it back in. If the extension doesn't exist in globalStorage it will then install it from the marketplace. Installing from the marketplace does take time, and if you've got a lot of extensions that need to come from there it'll take longer, but that shouldn't happen too frequently.

Ignoring Extensions

There may be extensions that you always want installed, your preferred themes for example. There are also some extensions that the removal of can be problematic or they are quite large, such as Live Share.

You don't really want to make sure they are in every single profile, so instead I've added a setting called profileSwitcher.extensionsIgnore. This is an array of extension ID's that you want to be in every profile and by default I have these set to be ignored:

shan.code-settings-sync
ms-vsliveshare.vsliveshare
ms-vsliveshare.vsliveshare-audio
ms-vsliveshare.vsliveshare-pack

Enter fullscreen mode Exit fullscreen mode

If you want to add more you'll need to edit your settings.json file and add the setting. If you do manually set the setting you'll need include those 4 above (assuming you want to keep ignoring them), as that's the default until manually set.

Note on Upgrading

Just a quick note when upgrading to the latest release, if you saved a profile prior to 0.3.0 it will have no extensions associated with it, so you'll want to resave that profile, otherwise when you switch it'll think you don't have any associated extensions in the profile and remove all of yours (see bug #6).

Wrap Up

I was really happy to get this feature landed because nearly everyone asked me about it when I first released it! It was a little tricky, VS Code doesn't really provide an API for doing this kind of stuff with extensions (can't blame them, you don't want to make it easy for extensions to manipulate other extensions!) but it seems to be working well now in the 0.3.3 release.

If you are using the extension I'd love to hear about it, know the kinds of things it's helping you with and what features you'd like to see in the future.

Top comments (14)

Collapse
 
jefrypozo profile image
Jefry Pozo

It is a good idea. How did I never thought of it?

Jokes aside, I'm curious. Why do you remove the extensions instead of disabling them?
Doesn't disabling them accomplish the goal of getting down the memory footprint and/or load times?

Collapse
 
aaronpowell profile image
Aaron Powell Author

It would, but unfortunately there's no API that's exposed to extensions that allows you to disable an extension.

I did some digging around the VS Code source and it looks like disabling extensions requires writing to one of the databases that VS Code uses internally, not just setting some config flags or anything.

Because of that I decided I wouldn't try and disable (don't want to risk corrupting the database) the extensions, just remove them.

Collapse
 
aaronpowell profile image
Aaron Powell Author

Interesting aside - when you disable an extension in VS Code it isn't returns in the list of extensions that the extensions API has access to.

Collapse
 
jefrypozo profile image
Jefry Pozo

I see. Microsoft is known for making extensions development complicated sometimes.

Anyway, it is a good extension. Keep the good work. πŸ‘

Thread Thread
 
aaronpowell profile image
Aaron Powell Author

It's a fine balance between performance, extensibility and reliability.

I do agree that you don't want to have extensions that can easily interfere with the operation of other extensions, if it was easy to disable extensions then you could end up with a malicious extension author messing with what's loaded.

Similarly, the more of the internals available to an extension the more you risk startup penalties because you have to make a larger sandbox.

Browsers suffer a similar problem, the more they allow you to do in an extension the more it risks the performance of the browser, and it's more often than not the browser that the finger gets pointed at than the extension.

Thread Thread
 
jefrypozo profile image
Jefry Pozo

I agree with you on those points. I haven't really looked into VSCode extensibility, but I had a sour experience with Visual Studio when developing an extension for changing text editor colors.

But nonetheless, I think the ability to disable extensions has a lesser impact than removing extensions if security is the concern. Said in another way, I believe being able to remove them is worst than being able to disable them.

Collapse
 
equiman profile image
Camilo Martinez

I'm waiting for something like that for months.

Thank's ... I will test it.

Collapse
 
aaronpowell profile image
Aaron Powell Author

Let me know how it goes for you and if there's anything you want from it 😁

Collapse
 
equiman profile image
Camilo Martinez

Could you explain better how SyncExtension deal with this?

Upload the current profile? Or upload all profiles?

Thread Thread
 
aaronpowell profile image
Aaron Powell Author

Are you referring to Settings Sync?

Settings Sync works by taking a copy of your settings.json and uploading it to a gist, along with the metadata of your currently active extensions (and a few other pieces).

Since my extension also uses the settings.json file to store everything they'll get uploaded with Settings Sync. I actually use that myself to sync between VS Code and VS Code Insiders (easiest way to have 2 independent installs!).

Thread Thread
 
equiman profile image
Camilo Martinez

OK, perfect. This weekend I'll create my profiles: Vanilla JS/Angular/.Net. :D

Thanks!

Thread Thread
 
equiman profile image
Camilo Martinez • Edited on

I already tested your extension, thanks for your work it's amazing. It's a good way to deal with extensions on vscode.

I have some comments about, after tested.

  1. I think "profileSwitcher.storage" it's unnecessary because vscode have 2 files for configuration.
    User configuration for general purpose and project settings (.vscode/settings.json) for specific configurations. Then you can setup those changes on this files.
    I understand some user can found it useful and I'll recommend add a property to disable with a property.

  2. I have a problem when work with two kind of projects (C# and Web), because when switch between profiles are installing and uninstalling extensions but this apply to all vscode session. That's how works vscode currently and it's not the extension fault, you can use it, but can't work on different kind of projects.
    Instead of install and uninstall I think a solution can be save on each profile a list of extensions to disable. When switch to this profiles, disable those extension on current project. But i have no idea how difficult is do that.
    Until that a workaround could be work one session on vscode and other on insiders version.

  3. ΒΏIt's there a way to add a property on project setting (.vscode/settings.json) to select automatically a Profile?

Thanks again. Amazing job!
Let me know if can help testing something.

Thread Thread
 
aaronpowell profile image
Aaron Powell Author

Thanks for the feedback Camilo, I'll answer in reverse order (and they are easier to answer that way!).

3. Currently no, the only "auto-select" for a profile is when you go into Live Share. That said, it's something I was thinking about last week and may add if there's demand (would just need to work out how best to do it).

2. Alas there's no way for me to disable extensions, it's uninstall or nothing, see this comment: dev.to/aaronpowell/comment/dd3a

1. I made a deliberate decision to not use the .vscode/settings.json file as the place I update for a few reasons. The main reason is that I don't want to do anything that runs the risk of corrupting the current git repo. If the extension updated a file tracked in git then it's a (potential) commit you have to make and a diff that needs to be explained. I'd prefer to not do anything that run the risk of modifying a file that everyone on the team relies on.

Another reason is that I originally wrote this extension for when I give talks. I have to remember to switch my settings to make it optimised for viewing on a projector, and I want those settings across all instances I have open (I may use several demos in a talk). So yes, it was partially built around a workflow I needed.

Lastly, you can already do workspace-specific settings by just using the .vscode/settings.json to what you need (I use to do that for repos explicitly used for presenting), so I didn't want to replicate functionality that already exists.

Hope that explains my thought process/reasoning behind some decisions. 😊

Collapse
 
jsjoeio profile image
Joe Previte (he/him)

Nice work, Aaron! :D Thanks again for making this. I've started using it to help me learn vim.

i.e. I have one profile for vim and another for my regular setup. Makes it really easy to switch back and forth!

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.