Computed settings in VS Code.
This is a work in progress. Configuration files may be lost, so please make sure to back them up.
A configuration file (such as .vscode/settings.json
or the user's preferences)
may import other configuration files using the imports
option as follows:
{
"computed-settings.imports": [
"./foo.jsonc"
],
"editor.tabSize": 3
}
The imported files will then be resolved relatively to the configuration file,
and their configuration will be flattened. Assuming that foo.jsonc
contains
the following:
{
"editor.minimap.enabled": true,
"editor.tabSize": 5
}
Then the initial file will be updated like this:
{
"computed-settings.imports": [
"./foo.jsonc"
],
"editor.tabSize": 3,
// #region Generated by https://github.com/71/computed-settings
"editor.minimap.enabled": true
// #endregion Generated by https://github.com/71/computed-settings
}
Please note:
- The current configuration takes precedence over imported configurations; i.e.
editor.tabSize
is not replaced by the imported value. - Configurations are imported recursively, i.e.
foo.jsonc
may also have imports above. - If multiple imports are specified, they are merged as follows:
- Arrays are merged shallowly, i.e. only top-level arrays are merged.
- Latter imports take precedence over former ones when a choice must be made, i.e. when a property is not assigned to an array.
Note: I wrote this not knowing that settings schemas can be used directly from arbitrary JSON files, so the section below is mostly useless. When editing settings, use one of the following schemas:
vscode://schemas/settings/folder
vscode://schemas/keybindings
Other schemas are also available, and listed in the "Feature contributions" tab
of the "Configuration Editing" built-in extension
(vscode.configuration-editing
).
Old documentation
JSON Schemas corresponding to the possible configuration values can be generated and written to the disk.
There are two ways to generate the configuration on disk:
- In a JSON file, start typing
"$schema":
at the start of the file (after{
); a completion"$schema": "..."
will be made available. If you select it, the schema will be generated in the same directory under the name.computed-settings.schema.json
.- After generating this line, a quick-fix will also be available on this line to update the generated file.
- In
settings.json
, add ajson.schemas
with an entry whose file name ends withcomputed-settings.schema.json
, e.g.When this option is present, a schema will automatically be generated. Note that the{ "json.schemas": [ { "fileMatch": [ "*.jsonc" ], "url": ".vscode/.computed-settings.schema.json" } ] }
url
is resolved relatively to the workspace root.
Note: these schemas are generated using the configuration options of VS Code at a given version (as of now, 1.77), and combining them with the configuration options provided by the currently loaded extensions. If extensions change or if the included VS Code config schema is out of date, the generated schema may not entirely be accurate.
The following features are partially implemented, with possible errors and poor diagnostics.
To provide more power to computed settings, Nickel file may also be imported.
Features:
- Nickel files can be imported, and may import other Nickel files
- Errors are reported as diagnostics in VS Code
- Schema generation for Nickel files
- Using schema information to allow dotted properties
To import Nickel files, simply specify a .ncl
extension when importing a file:
{
"computed-settings.imports": [
"./foo.ncl",
"./bar.json"
]
}
Since files other than settings.json
may benefit from being cut into multiple
files, an importInto
option is provided as well:
{
"computed-settings.importInto": {
"tasks.json": [
"./shared-tasks.json"
],
"keybindings.json": [
"../shared-keybindings.json"
]
}
}
This will perform the same import process as imports
, but the computed
configuration will be appended to the specified files.
- Tests:
- Import tests.
- Import-into tests.
- Schema generation tests.
- Array-merging tests.
- Ensuring that it works in VSCodium.
- Ensuring that it works in remote contexts and in the browser.
- Gotchas:
- Recursive imports
- Shared imports
- Non-relative imports
- Computation in JSON strings:
- Evaluation of
${env:...}
/${workspaceFolder}
interpolations - Conditionals
- Special
${import:}
interpolations
- Evaluation of
- More languages:
- YAML
- TOML
- (Maybe) Jsonnet, Cue, Dhall
- Other merging strategies:
- (Maybe) Merge up to a specified depth
- (Maybe) Merge using schema information
- Schema generation:
- Show quick-fix in
settings.json
underjson.schemas
to refresh the generated schema - Detect whether the generated schema is out-of-date and only display a quick-fix if it is
- Support for other files:
keybindings.json
tasks.json
launch.json
- Show quick-fix in