Configuration System
There are two types of configuration types.
- editor configuration (editor)
- project configuration (project)
The editor configuration is used to store some editor-related user settings and data, and is divided into three priority levels, from high to low, as follows.
If there is no corresponding configuration in , the configuration in global
will be used, and if no corresponding configuration in global
is found, the default default
configuration will be used.
Project Configuration
The project configuration is used to store some project-related user settings and data, and is divided into two priority levels, from highest to lowest.
local -> default
To use the configuration system, you need to define the profile
information in the contributions
field of the extension definition file package.json
, as follows.
{
"contributions": {
"profile": {
"editor": {
"test.a": {
"default": 0,
"message": "editorTestAChanged",
"label": "Test Editor configuration"
}
},
"test.a": {
"default": 1,
"message": "projectTestAChanged",
"label": "Test Project Configuration"
}
}
},
}
contributions.profile The related fields are interpreted as follows.
editor
:{} - editor configurationproject
:{} - project configurationtest.a
:{} - key for the configuration of test.adefault
:any - the default value of this configuration item, optional parametermessage
:string - the message that will be triggered when this configuration item is modified, optionallabel
:string - where the configuration can be displayed, this description may be displayed. Supports i18n:key format, optional parameters
The TypeScript interface associated with profile
is defined as follows.
import packageJSON from '../package.json';
If the last parameter of Editor.Profile.getConfig
is empty, a priority match will be performed.
await Editor.Profile.getConfig(packageJSON.name, 'test.a'); // 0
await Editor.Profile.getConfig(packageJSON.name, 'test.a', 'local'); // undefined
await Editor.Profile.getConfig(packageJSON.name, 'test.a', 'global'); // undefined
Modify the Editor Configuration
Call getConfig
after modifying the configuration with the following code to see the corresponding changes.
If the last parameter of Editor.Profile.getProject
is empty, a match will be performed.
If the fetch location (either local
, default
) is specified, the corresponding value will be returned. As shown below, the local
is undefined
because it is not set.
await Editor.Profile.getProject(packageJSON.name, 'test.a'); // 1
await Editor.Profile.getProject(packageJSON.name, 'test.a', 'local'); // undefined
Modify the Project Configuration
Call getProject
after modifying the configuration with the following code to see the corresponding changes.
await Editor.Profile.setProject(packageJSON.name, 'test.a', 1);
await Editor.Profile.setProject(packageJSON.name, 'test.a', 'local', 2);
Project Configuration Storage Path
Hierarchy | Path |
---|---|
local | {projectPath}/settings/v2/extensions/{extensionName}.json |
default |