上级 c28c86fc
......@@ -249,23 +249,19 @@ class FormatOnSaveParticipant implements ITextFileSaveParticipant {
const editorOrModel = findEditor(textEditorModel, this.codeEditorService) || textEditorModel;
const mode = this.configurationService.getValue<'file' | 'modifications' | 'modificationsIfAvailable'>('editor.formatOnSaveMode', overrides);
// keeping things DRY :)
const formatWholeFile = async () => {
if (mode === 'file') {
await this.instantiationService.invokeFunction(formatDocumentWithSelectedProvider, editorOrModel, FormattingMode.Silent, nestedProgress, token);
};
if (mode === 'modifications' || mode === 'modificationsIfAvailable') {
// try formatting modifications
} else {
const ranges = await this.instantiationService.invokeFunction(getModifiedRanges, isCodeEditor(editorOrModel) ? editorOrModel.getModel() : editorOrModel);
if (ranges) {
// version control reports changes
if (ranges === null && mode === 'modificationsIfAvailable') {
// no SCM, fallback to formatting the whole file iff wanted
await this.instantiationService.invokeFunction(formatDocumentWithSelectedProvider, editorOrModel, FormattingMode.Silent, nestedProgress, token);
} else if (ranges) {
// formatted modified ranges
await this.instantiationService.invokeFunction(formatDocumentRangesWithSelectedProvider, editorOrModel, ranges, FormattingMode.Silent, nestedProgress, token);
} else if (ranges === null) {
// version control not found
await formatWholeFile();
}
} else {
await formatWholeFile();
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册