Reputation: 275
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,
...
}
Upvotes: 2
Views: 2436
Reputation: 181170
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.
Upvotes: 4