From 33eeacb3ba30fd7579d1fc32f4b560cf797496b2 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 22 May 2019 09:49:14 +0200 Subject: [PATCH] debt - use editor cancellation token for all formatting commands --- src/vs/editor/contrib/format/format.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/vs/editor/contrib/format/format.ts b/src/vs/editor/contrib/format/format.ts index 261d86ba74b..a972452a11d 100644 --- a/src/vs/editor/contrib/format/format.ts +++ b/src/vs/editor/contrib/format/format.ts @@ -8,7 +8,7 @@ import { isNonEmptyArray } from 'vs/base/common/arrays'; import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation'; import { illegalArgument, onUnexpectedExternalError } from 'vs/base/common/errors'; import { URI } from 'vs/base/common/uri'; -import { CodeEditorStateFlag, EditorState, EditorStateCancellationTokenSource, TextModelCancellationTokenSource } from 'vs/editor/browser/core/editorState'; +import { CodeEditorStateFlag, EditorStateCancellationTokenSource, TextModelCancellationTokenSource } from 'vs/editor/browser/core/editorState'; import { IActiveCodeEditor, isCodeEditor } from 'vs/editor/browser/editorBrowser'; import { registerLanguageCommand, ServicesAccessor } from 'vs/editor/browser/editorExtensions'; import { Position } from 'vs/editor/common/core/position'; @@ -143,27 +143,25 @@ export async function formatDocumentRangeWithProvider( const workerService = accessor.get(IEditorWorkerService); let model: ITextModel; - let validate: () => boolean; + let cts: CancellationTokenSource; if (isCodeEditor(editorOrModel)) { model = editorOrModel.getModel(); - const state = new EditorState(editorOrModel, CodeEditorStateFlag.Value | CodeEditorStateFlag.Position); - validate = () => state.validate(editorOrModel); + cts = new EditorStateCancellationTokenSource(editorOrModel, CodeEditorStateFlag.Value | CodeEditorStateFlag.Position, token); } else { model = editorOrModel; - const versionNow = editorOrModel.getVersionId(); - validate = () => versionNow === editorOrModel.getVersionId(); + cts = new TextModelCancellationTokenSource(editorOrModel, token); } const rawEdits = await provider.provideDocumentRangeFormattingEdits( model, range, model.getFormattingOptions(), - token + cts.token ); const edits = await workerService.computeMoreMinimalEdits(model.uri, rawEdits); - if (!validate()) { + if (cts.token.isCancellationRequested) { return true; }