diff --git a/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts b/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts index 9091dc3412a9bf8b98017c48e0c451e18e1253ba..59f93eb7f2f6d17281c2e786950c9a6c4e33c42d 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts @@ -215,16 +215,20 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant { const timeout = this._configurationService.getValue('editor.formatOnSaveTimeout', { overrideIdentifier: model.getLanguageIdentifier().language, resource: editorModel.getResource() }); return new Promise((resolve, reject) => { - setTimeout(() => reject(localize('timeout.formatOnSave', "Aborted format on save after {0}ms", timeout)), timeout); - getDocumentFormattingEdits(model, { tabSize, insertSpaces }) - .then(edits => this._editorWorkerService.computeMoreMinimalEdits(model.uri, edits)) - .then(resolve, err => { - if (!(err instanceof Error) || err.name !== NoProviderError.Name) { - reject(err); - } else { - resolve(); - } - }); + let request = getDocumentFormattingEdits(model, { tabSize, insertSpaces }); + + setTimeout(() => { + reject(localize('timeout.formatOnSave', "Aborted format on save after {0}ms", timeout)); + request.cancel(); + }, timeout); + + request.then(edits => this._editorWorkerService.computeMoreMinimalEdits(model.uri, edits)).then(resolve, err => { + if (!(err instanceof Error) || err.name !== NoProviderError.Name) { + reject(err); + } else { + resolve(); + } + }); }).then(edits => { if (!isFalsyOrEmpty(edits) && versionNow === model.getVersionId()) {