VSCode Extensions API — How to change nested settings using getConfiguration().update()?

Viewed 28

Is it possible to change nested settings using the VSCode Extensions API? I've searched around and there doesn't seem to be any discussion around this.

For example, how do I use getConfiguration().update() to change a setting like:

{
    "workbench.colorCustomizations": {
        "button.foreground": "#FFCC66", // <-- nested setting to change
        // ...rest of nested settings
    },
    // rest of settings
}

How do I go about accessing "deep" properties such as the nested button.foreground property using dotted notation?

await vscode.workspace
    .getConfiguration()
    .update(
        <nested-property>,
        '#ffffff', // new button foreground color
        vscode.ConfigurationTarget.Global
    );
1 Answers

Figured it out.

// Get configuration for parent setting
const colorCustomizations: any = await vscode.workspace
    .getConfiguration()
    .get('workbench.colorCustomizations');

// Update nested setting
colorCustomizations['button.foreground'] = '#ffffff';

// Overwrite entire parent setting
await vscode.workspace
    .getConfiguration()
    .update(
        'workbench.colorCustomizations',
         colorCustomizations,
         vscode.ConfigurationTarget.Global
    );

Thanks to @rioV8 for guiding me in the right direction.

Related