How to programmatically update lineHighlightBackground in vscode?

Viewed 136

I'm writing vscode extension. I want to update vscode configuration (doesn't matter if it's global or workspace config) programmatically, not manually.

The manual way works fine:

  1. I press F1
  2. I find >Preferences: Open Settings (JSON)
  3. I go inside "workbench.colorCustomizations"
  4. I update "editor.lineHighlightBackground" to "#1073cf2d".

Can I do it programmatically?

I tried this:

vscode.workspace.getConfiguration("workbench.colorCustomizations")
.update("editor.lineHighlightBackground", "#5e0a69");

But does not work.

2 Answers

This code works fine. I also added lineHighlightBorder changer next to the lineHighlightBackground changer.

let vvv: any = vscode.workspace
    .getConfiguration("workbench")
    .get("colorCustomizations");

vscode.workspace.getConfiguration("workbench").update(
    "colorCustomizations",
    {
        ...vvv,
        "editor.lineHighlightBackground": "#1073cf2d",
        "editor.lineHighlightBorder": "#9fced11f",
    },
    1,
);

The ”workbench.colorCustomizations” setting is an Object, so you can’t update just one line/property, but instead you must update the entire Object.

So, read the “workbench.colorCustomizations” setting (entire Object), manually update that property and later, update the “workbench.colorCustomizations” setting with the updated Object.

Related