How are extension developers allowing users to customize features like linting? - visual-studio-code

I'm working on a VSCode extension that has a linting feature. The linter can be customized quite a bit. How are folks allowing users to customize a feature like this? Completely in user preference settings? Specially named file? User preference setting that specifies path to a settings file?

It looks like you can have a .vscode\settings.json file that allows global user preferences to be overridden on a per-workspace basis.

Related

vscode setting for specific filename

I want to apply a setting for a specific file, the only answers I've seen for this topic have been language-specific settings. How can I achieve this?
At this time, you cannot achieve this natively. According to their documentation they state:
VS Code provides two different scopes for settings:
User Settings - Settings that apply globally to any instance of VS Code you open.
Workspace Settings - Settings stored inside your workspace and only apply when the workspace is opened.
You would have to file a feature request on their github for support

Copy enable/disable extensions settings to another workspace

Idea:
I wanted to clean up my vscode extensions, because I'm working with a lot of different languages/file types and having all these extensions installed and enabled at once is just too much.
Problem:
I disabled some extensions for a specific workspace, and wanted to copy these settings to another workspace, but vscode is not storing the information about enabled/disabled extensions in .vscode/settings.json.
Questions:
Is there any way to copy these settings from one workspace to another?
Is there a better way of dealing with lots of extensions?
Can you recommend tools/extensions for managing extensions per workspace or language(s)
I assume vscode is not loading all extensions at once, but rather when needed. But some extensions display icons on the left or bottom of the window and overcrowd the "Show All Commands" list/search.
VS Code stores this info in its internals instead of the .vscode folder, so you can't copy this info between workspaces. There is an open issue asking exactly what you want.
But, you have an alternative. Use the Profile Switcher extension.
Its description:
This extension allows you to define a number of settings profiles that you can easily switch between. The original idea for this extension came from my desire to have an easy way for me to switch my VS Code to a setup that was better optimised for presenting (changed themes, increase font size, etc).
And this is how it handles extensions:
A profile isn't just the settings you have enabled, but also the extensions that were installed. This allows you to create different profiles for different styles of development (e.g. a React profile and a Vue profile, loading their respective extensions only).
Hope this helps
There is a github issue for this problem: Feature Request: Enable/disable extensions from config file #40239.
I posted there a workaround using multiple vscode instances: link
Here is a copy-paste:
I use some kind of workaround to be able to use the extensions I want.
According to the vscode-cli your can specify the folders for extensions and user-data:
Options Description
--extensions-dir <dir> Set the root path for extensions.
--user-data-dir <dir> Specifies the directory that user data is kept in. Can be used to open multiple distinct instances of Code.
Basically, I create a specific folder for my specific tasks (one of front, one for back, ..) and set basic extensions to my default vscode.
To launch my custom config:
code --extensions-dir "$HOME/.vscode/profiles/my-super-profile/extensions" --user-data-dir "$HOME/.vscode/profiles/my-super-profile/data"
The problem are that:
It's not REALLY a project config file but a global preference file
I had to install manually the extensions. I believe there is a hackish way to do this
It use more size than necessary (multiple vscode data / duplicate extensions)
It doesn't solve in a clean way the team-sharing problem

Saving user preferences/settings for vscode extension

What are the best practices to store user settings for the extension? I can think of saving them in some specific format in the text file. Is there any integrated way of doing that using vscode API?
VSCode extensions typically contribute settings to be used in user and workspace settings.json files.
Settings are registered via contributes.configuration in an extension's package.json, and the allowed values can flexibly be described with a JSON schema (which also allows for code completion in the JSON file). The value of settings can then be checked by using the workspace.getConfiguration() API.
There is also a sample extension that showcases the Configuration API in vscode-extension-samples.
Having a separate file just for a specific extension's settings would be a bit unusual.

How to set which extensions are enabled when opening a new folder or workspace?

So I have a great many extensions, and on any given project, I find myself using maybe a third of all of them (If I'm working on a Python project, I don't really need JavaScript related extensions now do I?). The problem is that right now VS Code loads and enables every single extension installed at the start of each new project. I find it a pain to then have to manually go and disable all the extensions I won't be needing for the project.
Is there a way to setup VS Code to only enable certain extensions when opening a new folder / workspace? I couldn't find anything in the docs on that subject and when looking at the extension section of the preferences I couldn't find such a functionality.
As of Feb 2023, it is now possible to create different Profiles in VS Code.
A Profile can include extensions, settings, keyboard shortcuts, UI state, tasks, and user snippets. You can customize VS Code for different development scenarios like data science, documentation writing, or for multiple programming languages like Python or Java. If you have different VS Code setups based on workflow such as "Work" or "Demo", you can also save those as different profiles. You can open multiple workspaces (folders) with different profiles applied simultaneously.
The following image demonstrates a folder opened with a Work profile that is customized for a work setup.
To my knowledge, the best you can do is use the Enable, Enable (Workspace) and Disable, Disable (Workspace) options.
Here is how ended up doing this:
Open a new workspace / folder.
Disable all extensions using Disable.
Enable all extension that you want to have enabled in every new project with Enable.
Enable extensions that you only want to use in this particular workspace / folder with Enable (Workspace)
From then on, when you open a new workspace, only the "default" extensions should be enabled. If ever you want to disable one of these "default" extensions in a particular workspace but still want it to be a "default" extension, make sure to use the Disable (Workspace) option.

How to save VS Code settings and snippets files in another location

By default the user settings for VS Code are saved in c:\users\<username>\AppData\Roaming\Code\User. Is there a way to change that to save in a custom location? I'd like to save them in my OneDrive folder so my settings and snippets will roam.
Not directly answering the question of whether it is possible to change the path of the user settings (which is not possible as far as I know) but there is an extension which does the synchronization of settings and snippets.
Maybe this is an option for you.