Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double check pending markdown version before updating preview #73049

Merged
merged 2 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions extensions/markdown-language-features/src/features/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -389,18 +401,23 @@ 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);
}
return;
}
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);
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/vs/workbench/api/browser/mainThreadSaveParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down