提交 6e4fe5fb 编写于 作者: J Johannes Rieken

keep old setting as it and add dependent setting

上级 a87dc68f
......@@ -239,19 +239,23 @@ class FormatOnSaveParticipant implements ITextFileSaveParticipant {
)
});
});
const editorOrModel = findEditor(textEditorModel, this.codeEditorService) || textEditorModel;
const config = this.configurationService.getValue<boolean | string>('editor.formatOnSave', overrides);
if (config === true || config === 'file') {
// format the whole file
await this.instantiationService.invokeFunction(formatDocumentWithSelectedProvider, editorOrModel, FormattingMode.Silent, nestedProgress, token);
const enabled = this.configurationService.getValue<boolean>('editor.formatOnSave', overrides);
if (!enabled) {
return undefined;
}
} else if (config === 'modifications') {
const editorOrModel = findEditor(textEditorModel, this.codeEditorService) || textEditorModel;
const mode = this.configurationService.getValue<'file' | 'modifications'>('editor.formatOnSaveMode', overrides);
if (mode === 'modifications') {
// format modifications
const ranges = await this.instantiationService.invokeFunction(getModifiedRanges, isCodeEditor(editorOrModel) ? editorOrModel.getModel() : editorOrModel);
if (ranges) {
await this.instantiationService.invokeFunction(formatDocumentRangesWithSelectedProvider, editorOrModel, ranges, FormattingMode.Silent, nestedProgress, token);
}
} else {
// format the whole file
await this.instantiationService.invokeFunction(formatDocumentWithSelectedProvider, editorOrModel, FormattingMode.Silent, nestedProgress, token);
}
}
}
......
......@@ -360,21 +360,24 @@ configurationRegistry.registerConfiguration({
...editorConfigurationBaseNode,
properties: {
'editor.formatOnSave': {
'type': 'boolean',
'description': nls.localize('formatOnSave', "Format a file on save. A formatter must be available, the file must not be saved after delay, and the editor must not be shutting down."),
'scope': ConfigurationScope.LANGUAGE_OVERRIDABLE,
},
'editor.formatOnSaveMode': {
'type': 'string',
'default': 'off',
'default': 'file',
'enum': [
'off',
'file',
'modifications'
],
'enumDescriptions': [
nls.localize('off', "Disable format on save."),
nls.localize('everything', "Format the whole."),
nls.localize('everything', "Format the whole file."),
nls.localize('modification', "Format modifications (requires source control)."),
],
'description': nls.localize('formatOnSave', "Format a file on save. A formatter must be available, the file must not be saved after delay, and the editor must not be shutting down."),
scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,
}
'markdownDescription': nls.localize('formatOnSaveMode', "Controls if format on save formats the whole file or only modifications. Only applies when `#editor.formatOnSave#` is `true`."),
'scope': ConfigurationScope.LANGUAGE_OVERRIDABLE,
},
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册