Configuration system

When writing an extension, it may be necessary to save configurations and provide some configurations for users to customize settings. Therefore, a configuration management mechanism is provided in the editor.

Configuration Type

The configuration in the editor is divided into two types:

  1. Editor settings
  2. Project Settings

Editor settings

Store some editor-related function settings. This part is also the main configuration of the editor.

The editor settings are divided into three levels, with priority from high to low:

  1. local -> global -> default

Project Settings

Store some project-related configurations, which are allowed and need to be shared between projects.

  1. local -> default

Register Configuration

  1. {
  2. "name": "hello-world",
  3. "contributions": {
  4. "profile": {
  5. "editor": {
  6. "test.a": {
  7. "default": 0,
  8. "message": "editorTestAChanged",
  9. "label": "Test Editor Configuration"
  10. }
  11. },
  12. "project": {
  13. "test.a": {
  14. "default": 1,
  15. "message": "projectTestAChanged",
  16. "label": "Test project configuration"
  17. }
  18. }
  19. }
  20. },
  21. }
  1. interface ProfileInfo {
  2. editor: {[key: string ]: ProfileItem };
  3. project: {[key: string ]: ProfileItem };
  4. }
  5. interface ProfileItem {
  6. // Configured default data
  7. default: any;
  8. // After configuration changes, this message will be automatically sent to notify
  9. message: string;
  10. // Simply describe the role of configuration information, support i18n:key syntax
  11. label: string;
  12. }

contributions.profile is divided into editor and project configurations. The definitions of these two configurations are object objects. The key of the object is the key of the configuration, and the value is the basic information describing the configuration.

default

Type {any} optional

The default value of the configuration. It can be of any type.

message

Type {string} optional

When the message is modified, the defined message will be triggered. Used to dynamically update some data when configuration changes.

label

Type {string} optional

Briefly describe this configuration. Where the configuration can be displayed, this description may be displayed. Support i18n:key format

Read configuration

Read editor configuration

  1. const packageJSON = require('./package.json');
  2. // await Editor.Profile.getConfig(pkgName, key, protocol);
  3. await Editor.Profile.getConfig(packageJSON.name,'test.a'); // 0
  4. await Editor.Profile.getConfig(packageJSON.name,'test.a','local'); // undefined
  5. await Editor.Profile.getConfig(packageJSON.name,'test.a','global'); // undefined

Read project configuration

  1. const packageJSON = require('./package.json');
  2. // await Editor.Profile.getConfig(pkgName, key, protocol);
  3. await Editor.Profile.getProject(packageJSON.name,'test.a'); // 1
  4. await Editor.Profile.getProject(packageJSON.name,'test.a','project'); // undefined