Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code Extension to Update Workspace Settings

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.

like image 405
trebleCode Avatar asked Jan 24 '19 22:01

trebleCode


People also ask

How do I update VS Code settings?

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.

How do you refresh a workspace in VS Code?

To refresh the currently active viewChoose Refresh from the Window menu, or click the Refresh button in the toolbar.

How do I sync VS Code settings and extensions?

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.


1 Answers

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.

like image 175
greenharbour Avatar answered Oct 11 '22 18:10

greenharbour