Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vscode: is there an api for accessing config values from a vscode extension

I am writing an extension for vscode 1.12.2 and I am trying to determine the default theme. Atom Editor has a nice API for accessing config values, e.g.:

atom.config.defaultSettings.core.themes[0]
"one-dark-ui"
atom.config.defaultSettings.core.themes[1]
"one-dark-syntax"

Is there something similar to this in vscode?

I can see the value 'workbench.colorTheme' in ~/AppData/Roaming/Code/User/settings.json:

   // "terminal.integrated.shell.windows": "/Program Files/Git/bin/bash.exe"
    "terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
    "terminal.integrated.shellArgs.windows": [
        "/k",
        "C:\\Program Files\\Git\\bin\\bash.exe"
    ],
    "workbench.colorTheme": "Default Light+" <-- here

However, I'd rather not resort to a custom solution whereby I directly read the config file as JSON, especially since it allows non-default JSON values such as comments, which I would presumably have to pre-parse-out.

While this question is narrowly directed at determining the theme, it really applies to any config parm. I didn't see anything in the vscode html api or in browsing the typings file /c/Program Files (x86)/Microsoft VS Code/resources/app/out/vs/vscode.d.ts

like image 958
vt5491 Avatar asked May 24 '17 07:05

vt5491


People also ask

How do I access VS Code config?

To open the Settings editor, use the following VS Code menu command: On Windows/Linux - File > Preferences > Settings. On macOS - Code > Preferences > Settings.

Where is VS Code config stored?

The workspace settings file is located under the . vscode folder in your project.

How do I sync Visual Studio Code extensions and settings?

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.

What is Webview in VS Code?

This extension opens a browser preview for the editor to the side. This example shows VS Code Web being developed right inside VS Code. A Webview panel is used to render a browser-like window.


1 Answers

Did you try:

const workbenchConfig = vscode.workspace.getConfiguration('workbench')
const theme = workbenchConfig.get('colorTheme')

Here's the documentation on the configuration object: https://code.visualstudio.com/docs/extensionAPI/vscode-api#WorkspaceConfiguration

like image 117
Matt Bierner Avatar answered Oct 03 '22 18:10

Matt Bierner