Configuration Service
The Configuration Service (IConfigurationService) is a core platform service that manages all configuration settings in Visual Studio Code. It provides access to user, workspace, and folder-specific settings with support for overrides and multiple configuration targets.
Service Overview
The Configuration Service is defined insrc/vs/platform/configuration/common/configuration.ts:14 and provides a unified interface for reading and writing configuration values across different scopes.
Service Identifier
Dependency Injection
The Configuration Service is injected using VS Code’s dependency injection system:Core Methods
getValue()
Retrieves configuration values with support for sections and overrides.string
The configuration section to retrieve (e.g.,
editor.fontSize)IConfigurationOverrides
Overrides for resource or override identifier
updateValue()
Updates configuration values at different targets (user, workspace, folder).string
required
The configuration key to update
unknown
required
The new value (use
undefined to remove)ConfigurationTarget
Where to store the setting (USER, WORKSPACE, WORKSPACE_FOLDER, etc.)
IConfigurationOverrides
Resource or override identifiers for scoped updates
inspect()
Inspects a configuration key to see values at all scopes.string
required
The configuration key to inspect
IConfigurationOverrides
Resource or override identifier context
The
inspect() method is particularly useful for understanding configuration precedence and debugging why a particular value is active.reloadConfiguration()
Reloads configuration from disk.keys()
Retrieves all configuration keys organized by scope.Configuration Targets
Configuration can be stored at different levels:ConfigurationTarget Enum
ConfigurationTarget Enum
WORKSPACE_FOLDER- Folder-specific settingsWORKSPACE- Workspace settingsUSER_REMOTE- Remote user settingsUSER_LOCAL- Local user settingsAPPLICATION- Application settingsDEFAULT- Default values
Configuration Overrides
Overrides allow scoping configuration to specific contexts:Resource-Based Overrides
Resource-Based Overrides
Language-Based Overrides
Language-Based Overrides
Events
onDidChangeConfiguration
Fired when configuration changes.Configuration Data Model
IConfigurationValue<T>
IConfigurationValue<T>
Represents a configuration value at all scopes:
Common Use Cases
Reading User Preferences
Writing Settings Programmatically
Respecting Workspace Settings
Best Practices
Configuration Keys: Use dot-notation for configuration keys (e.g.,
editor.fontSize, files.autoSave). This creates a logical hierarchy in the settings UI.Event Listeners: Always dispose of configuration change listeners to prevent memory leaks. Use
affectsConfiguration() to filter relevant changes.Resource Context: When working with file-specific features, always pass the resource URI to
getValue() to respect workspace folder settings.Undefined vs Null: Setting a value to
undefined removes it and falls back to defaults. Use null if you need to explicitly store a null value.Related Services
- IWorkspaceContextService - Provides workspace and folder context
- IEnvironmentService - Provides paths to settings files
- IFileService - Used internally to read/write settings files