Settings System
Relevant source files
The following files were used as context for generating this wiki page:
- extensions/markdown-language-features/package.json
- extensions/markdown-language-features/package.nls.json
- extensions/typescript-language-features/package.nls.json
- extensions/css-language-features/package.nls.json
- extensions/extension-editing/package.json
- extensions/make/package.json
- extensions/markdown-math/package.json
- extensions/yaml/syntaxes/yaml.tmLanguage.json
The VS Code Settings System provides a robust framework for extensions to declare configurable options that users can modify to customize the editor's behavior. This system is primarily declarative, with extensions contributing their settings via the package.json manifest file. These settings are then exposed to the user through the Settings UI and settings.json files.
The system supports various data types, scopes (resource, window), and default values. It also integrates with localization files (package.nls.json) to provide human-readable names and descriptions for all contributed settings. This allows for a consistent and discoverable user experience across all extensions.
Core Concepts
The foundation of the settings system relies on two key files within an extension: package.json for declaration and package.nls.json for localization.
Configuration Contribution Point
Extensions declare their settings under the contributes.configuration property in their package.json file. This is typically an object or an array of objects, each with a title and a properties map.
title: A human-readable grouping for the settings, often corresponding to the extension's name (e.g., "Markdown", "CSS").properties: An object where each key is a unique setting identifier (e.g.,markdown.preview.breaks) and the value is an object defining the setting's schema.
The schema for each setting property includes attributes like type, default, description, and scope.
Sources: extensions/markdown-language-features/package.json:281-285, extensions/markdown-math/package.json:57-60
This diagram illustrates the basic structure of a configuration contribution.
Localization with package.nls.json
To support multiple languages and keep package.json clean, human-readable strings are stored in package.nls.json. In package.json, descriptions and titles are referenced using keys surrounded by percent signs (e.g., %markdown.preview.breaks.desc%). The build process and runtime then replace these keys with the corresponding values from the localization file.
For example, markdown.preview.breaks.desc in package.json maps to a detailed description in package.nls.json.
package.json snippet:
"markdown.preview.breaks": {
"type": "boolean",
"default": false,
"markdownDescription": "%markdown.preview.breaks.desc%",
"scope": "resource"
}
package.nls.json entry:
"markdown.preview.breaks.desc": "Sets how line-breaks are rendered in the Markdown preview. Setting it to `true` creates a `<br>` for newlines inside paragraphs."
Sources: extensions/markdown-language-features/package.json:291, extensions/markdown-language-features/package.nls.json:5, extensions/typescript-language-features/package.nls.json
Configuration Defaults
Extensions can also provide default editor settings for the languages they support using the contributes.configurationDefaults point. This is useful for setting language-specific behaviors like word wrap or indentation. These defaults are applied when a file of the specified language is active but can be overridden by the user.
For example, the Markdown extension enables word wrap by default for Markdown files.
"configurationDefaults": {
"[markdown]": {
"editor.wordWrap": "on",
"editor.quickSuggestions": {
"comments": "off",
"strings": "off",
"other": "off"
}
}
}
Sources: extensions/markdown-language-features/package.json:491-500, extensions/make/package.json:34-38
Language-Specific Settings
Settings are typically prefixed with a namespace corresponding to the feature or language they control, such as typescript., markdown., css., or scss.. This namespacing prevents conflicts and organizes settings logically.
Example Settings Across Features
The table below shows a variety of settings from different language feature extensions, demonstrating the breadth of configurability.
| Setting ID | Feature | Type | Default Value | Description | Source File |
|---|---|---|---|---|---|
typescript.format.enable | TypeScript | boolean | (not specified) | Enable/disable default TypeScript formatter. | extensions/typescript-language-features/package.nls.json:28 |
markdown.preview.scrollPreviewWithEditor | Markdown | boolean | true | When a Markdown editor is scrolled, update the view of the preview. | extensions/markdown-language-features/package.json:313-317 |
css.lint.duplicateProperties | CSS | string | (not specified) | Do not use duplicate style definitions. | extensions/css-language-features/package.nls.json:10 |
scss.format.braceStyle | SCSS | string | (not specified) | Put braces on same line (collapse) or on own line (expand). | extensions/css-language-features/package.nls.json:76 |
markdown.math.enabled | Markdown Math | boolean | true | Enable or disable math rendering in the Markdown preview. | extensions/markdown-math/package.json:61-65 |
Validation and Schemas
The settings system includes a mechanism for validating common configuration files using JSON schemas. The extension-editing extension contributes these validations via the contributes.jsonValidation point in its package.json.
This feature associates file patterns (e.g., package.json, *color-theme.json) with specific schema URLs. When a user opens a matching file, VS Code uses the schema to provide IntelliSense, hover information, and validation diagnostics.
Sources: extensions/extension-editing/package.json:31-57
JSON Validation Flow
The following diagram shows how a JSON file is validated against a contributed schema.
Contributed Schemas
The extension-editing extension provides schemas for several core VS Code file types:
| File Match Pattern | Schema URL | Purpose |
|---|---|---|
package.json | vscode://schemas/vscode-extensions | Validates extension manifests. |
*language-configuration.json | vscode://schemas/language-configuration | Validates language configuration files. |
*icon-theme.json | vscode://schemas/icon-theme | Validates file icon theme files. |
*product-icon-theme.json | vscode://schemas/product-icon-theme | Validates product icon theme files. |
*color-theme.json | vscode://schemas/color-theme | Validates color theme files. |
Sources: extensions/extension-editing/package.json:32-57
Conclusion
The VS Code Settings System is a cornerstone of the editor's extensibility model. By leveraging declarative contributions in package.json, it allows extension developers to easily add new configurations that are automatically integrated into the editor's UI and validation systems. The use of localization files ensures these settings are accessible to a global audience, while JSON schema validation maintains the integrity of important configuration files. This well-defined system empowers both users and developers to tailor the editor to their specific needs.