只读格式的所有默认值
如果您只想查看所有默认设置,请使用命令面板 (Ctrl+Shift+P) 并运行“首选项:打开默认设置 (JSON)”。VSCode 将生成所有默认值的 JSON 描述。
默认值来自哪里
默认设置是硬编码在 vscode 源代码中的。
细节
让我们看一些例子。当我打开设置时,我看到一个长长的列表,它位于顶部:
第一个条目是“文件:自动保存”。这是由 files.contribution.ts 中的 Typescript 代码片段定义的:
'files.autoSave': {
'type': 'string',
'enum': [AutoSaveConfiguration.OFF, AutoSaveConfiguration.AFTER_DELAY, AutoSaveConfiguration.ON_FOCUS_CHANGE, AutoSaveConfiguration.ON_WINDOW_CHANGE],
'markdownEnumDescriptions': [
nls.localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'files.autoSave.off' }, "A dirty file is never automatically saved."),
nls.localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'files.autoSave.afterDelay' }, "A dirty file is automatically saved after the configured `#files.autoSaveDelay#`."),
nls.localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'files.autoSave.onFocusChange' }, "A dirty file is automatically saved when the editor loses focus."),
nls.localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'files.autoSave.onWindowChange' }, "A dirty file is automatically saved when the window loses focus.")
],
'default': platform.isWeb ? AutoSaveConfiguration.AFTER_DELAY : AutoSaveConfiguration.OFF,
'markdownDescription': nls.localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'autoSave' }, "Controls auto save of dirty files. Read more about autosave [here](https://code.visualstudio.com/docs/editor/codebasics#_save-auto-save).", AutoSaveConfiguration.OFF, AutoSaveConfiguration.AFTER_DELAY, AutoSaveConfiguration.ON_FOCUS_CHANGE, AutoSaveConfiguration.ON_WINDOW_CHANGE, AutoSaveConfiguration.AFTER_DELAY)
},
注意这个default值,它顺便取决于isWeb变量。由于我在 Windows 上运行 VSCode(isWeb显然是错误的),我看到此属性的默认值为“off”。
下一个属性是“文件:自动保存延迟”。碰巧的是,同一文件中的下一个片段包含它:
'files.autoSaveDelay': {
'type': 'number',
'default': 1000,
'markdownDescription': nls.localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'autoSaveDelay' }, "Controls the delay in ms after which a dirty file is saved automatically. Only applies when `#files.autoSave#` is set to `{0}`.", AutoSaveConfiguration.AFTER_DELAY)
},
同样,GUI 中的默认值 1000 来自default此处的属性。
下一个属性是“编辑器:字体大小”。它来自commonEditorConfig.ts:
'editor.fontSize': {
'type': 'number',
'default': EDITOR_FONT_DEFAULTS.fontSize,
'description': nls.localize('fontSize', "Controls the font size in pixels.")
},
这里,默认值不是文字,所以我们必须追查EDITOR_FONT_DEFAULTS.fontSize. 在这里,在editorOptions.ts中:
export const EDITOR_FONT_DEFAULTS = {
fontFamily: (
platform.isMacintosh ? DEFAULT_MAC_FONT_FAMILY : (platform.isLinux ? DEFAULT_LINUX_FONT_FAMILY : DEFAULT_WINDOWS_FONT_FAMILY)
),
fontWeight: 'normal',
fontSize: (
platform.isMacintosh ? 12 : 14
),
lineHeight: 0,
letterSpacing: 0,
};
有趣的是,默认值取决于平台。由于我没有在 Mac 上运行,我看到默认值为 14。
等等。每个默认设置都来自 Typescript 源代码,或者在某些情况下来自package.json扩展文件(内置或由用户安装)。