2

I am building a vscode extension, where i needed the content of settings.json file. I tried the below one to get a specific value like colorTheme,

const workSpaceConfig = vscode.workspace.getConfiguration("editor"); console.log(workSpaceConfig.get("fontSize")); // which returns 14 

What if want the whole content which is in settings.json, like the below.

Settings.json (Example),

{ "workbench.colorTheme": "Quiet Light", "workbench.iconTheme": "material-icon-theme", "editor.fontSize": 14, "editor.formatOnSave": true, ... } 
5
  • How are you going to use them? What form do they need to be in? Commented Sep 8, 2021 at 16:54
  • what happens with vscode.workspace.getConfiguration(); Commented Sep 8, 2021 at 18:11
  • 1
    Most extensions consume each of the settings they are interested in one by one. If you simply want the whole JSON file content, read it from the workspace folder. In short, the whole content is useless as the hierarchical configuration system has settings in other files as well. Commented Sep 8, 2021 at 18:47
  • @rioV8 codebeautify.org/jsonviewer/cbcf4c50 Commented Sep 8, 2021 at 18:50
  • @LexLi Hmm ok.. Commented Sep 8, 2021 at 18:51

1 Answer 1

4

This might get you started, although it is unclear how you plan to use the returned information.

 let all = await vscode.workspace.getConfiguration(); let allAsJSON = JSON.parse(JSON.stringify(all)); // the key line const editorSettings = allAsJSON.editor; // ==> // { // tabSize: 2, // fontSize: 12, // insertSpaces: true, // detectIndentation: false, // trimAutoWhitespace: true, // largeFileOptimizations: true, // semanticHighlighting: { // enabled: "configuredByTheme", // }, // <etc.> // } const editorFontSizeSetting = editorSettings.fontSize; // 14 // all["editor"].fontSize ==> 14 // this also works 

The alternative is to find the settings.json file, JSON.parse() it.

As @LexLi intimated in his comment, user settings can be overridden by workplace settings for example.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.