I have been combing through VS Code API docs, and am trying to understand whether or not it is actually feasible to write an extension that can edit the global User Settings JSON file.
Am I correct in thinking that I can create my extension, add the metadata I'm after under the "contributes" section in the "configuration" child object, then based on those values when the plugin is activated, take action against the User's preferences JSON?
I've also looked at the Guides plugin's configuration to check other examples, I'm just having a hard time conceptualizing how all this works, so any pointers would be appreciated.
I'm definitely NOT asking for someone to write my extension, just provide an answer as to whether I'm understanding the mechanics of an extension as a developer.
To modify user settings, you'll use the Settings editor to review and change VS Code settings. To open the Settings editor, use the following VS Code menu command: On Windows/Linux - File > Preferences > Settings. On macOS - Code > Preferences > Settings.
To refresh the currently active viewChoose Refresh from the Window menu, or click the Refresh button in the toolbar.
You can turn on Settings Sync using the Turn On Settings Sync... entry in the Manage gear menu at the bottom of the Activity Bar. You will be asked to sign in and what preferences you would like to sync; currently Settings, Keyboard Shortcuts, Extensions, User Snippets, and UI State are supported.
Would this work?
import { ConfigurationTarget, workspace } from 'vscode';
const configuration = workspace.getConfiguration(<YOUR_SECTION>);
configuration.update(<SETTING_NAME>, <SETTING_VALUE>, ConfigurationTarget.Global).then(() => {
// take action here
});
More information about the WorkspaceConfiguration
object located here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With