From 98f383f9aa952a781edd7d93456294c45a93faa1 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 29 Apr 2019 11:07:35 -0700 Subject: [PATCH 1/2] Use finally --- src/vs/workbench/api/browser/mainThreadSaveParticipant.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/vs/workbench/api/browser/mainThreadSaveParticipant.ts b/src/vs/workbench/api/browser/mainThreadSaveParticipant.ts index 27ae35cfcd5..768c8283037 100644 --- a/src/vs/workbench/api/browser/mainThreadSaveParticipant.ts +++ b/src/vs/workbench/api/browser/mainThreadSaveParticipant.ts @@ -289,11 +289,8 @@ class CodeActionOnSaveParticipant implements ISaveParticipant { reject(localize('codeActionsOnSave.didTimeout', "Aborted codeActionsOnSave after {0}ms", timeout)); }, timeout)), this.applyOnSaveActions(model, codeActionsOnSave, tokenSource.token) - ]).then(() => { + ]).finally(() => { tokenSource.cancel(); - }, (e) => { - tokenSource.cancel(); - return Promise.reject(e); }); } From 4470b868a3281ddf55101dc4bf3b3905efa19f45 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 29 Apr 2019 13:49:36 -0700 Subject: [PATCH 2/2] Check pending version before updating markdown preview content For #72671 --- .../src/features/preview.ts | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/extensions/markdown-language-features/src/features/preview.ts b/extensions/markdown-language-features/src/features/preview.ts index 8b324579c14..0bb67dccd4c 100644 --- a/extensions/markdown-language-features/src/features/preview.ts +++ b/extensions/markdown-language-features/src/features/preview.ts @@ -60,6 +60,18 @@ interface PreviewStyleLoadErrorMessage extends WebviewMessage { }; } +export class PreviewDocumentVersion { + public constructor( + public readonly resource: vscode.Uri, + public readonly version: number, + ) { } + + public equals(other: PreviewDocumentVersion): boolean { + return this.resource.fsPath === other.resource.fsPath + && this.version === other.version; + } +} + export class MarkdownPreview extends Disposable { public static viewType = 'markdown.preview'; @@ -71,7 +83,7 @@ export class MarkdownPreview extends Disposable { private throttleTimer: any; private line: number | undefined = undefined; private firstUpdate = true; - private currentVersion?: { resource: vscode.Uri, version: number }; + private currentVersion?: PreviewDocumentVersion; private forceUpdate = false; private isScrolling = false; private _disposed: boolean = false; @@ -389,7 +401,8 @@ export class MarkdownPreview extends Disposable { return; } - if (!this.forceUpdate && this.currentVersion && this.currentVersion.resource.fsPath === resource.fsPath && this.currentVersion.version === document.version) { + const pendingVersion = new PreviewDocumentVersion(resource, document.version); + if (!this.forceUpdate && this.currentVersion && this.currentVersion.equals(pendingVersion)) { if (this.line) { this.updateForView(resource, this.line); } @@ -397,10 +410,14 @@ export class MarkdownPreview extends Disposable { } this.forceUpdate = false; - this.currentVersion = { resource, version: document.version }; + this.currentVersion = pendingVersion; if (this._resource === resource) { const content = await this._contentProvider.provideTextDocumentContent(document, this._previewConfigurations, this.line, this.state); - this.setContent(content); + // Another call to `doUpdate` may have happened. + // Make sure we are still updating for the correct document + if (this.currentVersion && this.currentVersion.equals(pendingVersion)) { + this.setContent(content); + } } }