From 825680cf03c8fae03fba14152475c0e5e2d541b5 Mon Sep 17 00:00:00 2001 From: Ole Date: Mon, 17 Jun 2024 17:04:53 +0200 Subject: [PATCH] Use MutableDisposable and await _updateThread. --- .../browser/view/cellParts/cellComments.ts | 40 +++++++++---------- test/automation/package.json | 4 +- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellComments.ts b/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellComments.ts index 7e4ad29842b4d..cbf886228ef67 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellComments.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellComments.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { coalesce } from 'vs/base/common/arrays'; -import { DisposableStore } from 'vs/base/common/lifecycle'; +import { DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle'; import { EDITOR_FONT_DEFAULTS, IEditorOptions } from 'vs/editor/common/config/editorOptions'; import * as languages from 'vs/editor/common/languages'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; @@ -20,7 +20,7 @@ import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange'; export class CellComments extends CellContentPart { - private _commentThreadWidget: CommentThreadWidget | null = null; + private readonly _commentThreadWidget = new MutableDisposable>; private currentElement: CodeCellViewModel | undefined; private readonly _commentThreadDisposables = this._register(new DisposableStore()); @@ -49,13 +49,12 @@ export class CellComments extends CellContentPart { } this.currentElement = element as CodeCellViewModel; - this._updateThread(); + await this._updateThread(); } private async _createCommentTheadWidget(owner: string, commentThread: languages.CommentThread) { - this._commentThreadWidget?.dispose(); this._commentThreadDisposables.clear(); - this._commentThreadWidget = this.instantiationService.createInstance( + this._commentThreadWidget.value = this.instantiationService.createInstance( CommentThreadWidget, this.container, this.notebookEditor, @@ -79,12 +78,12 @@ export class CellComments extends CellContentPart { const layoutInfo = this.notebookEditor.getLayoutInfo(); - await this._commentThreadWidget.display(layoutInfo.fontInfo.lineHeight, true); + await this._commentThreadWidget.value.display(layoutInfo.fontInfo.lineHeight, true); this._applyTheme(); - this._commentThreadDisposables.add(this._commentThreadWidget.onDidResize(() => { - if (this.currentElement?.cellKind === CellKind.Code && this._commentThreadWidget) { - this.currentElement.commentHeight = this._calculateCommentThreadHeight(this._commentThreadWidget.getDimensions().height); + this._commentThreadDisposables.add(this._commentThreadWidget.value.onDidResize(() => { + if (this.currentElement?.cellKind === CellKind.Code && this._commentThreadWidget.value) { + this.currentElement.commentHeight = this._calculateCommentThreadHeight(this._commentThreadWidget.value.getDimensions().height); } })); } @@ -98,29 +97,28 @@ export class CellComments extends CellContentPart { return; } const info = await this._getCommentThreadForCell(this.currentElement); - if (!this._commentThreadWidget && info) { + if (!this._commentThreadWidget.value && info) { await this._createCommentTheadWidget(info.owner, info.thread); const layoutInfo = (this.currentElement as CodeCellViewModel).layoutInfo; this.container.style.top = `${layoutInfo.outputContainerOffset + layoutInfo.outputTotalHeight}px`; - this.currentElement.commentHeight = this._calculateCommentThreadHeight(this._commentThreadWidget!.getDimensions().height); + this.currentElement.commentHeight = this._calculateCommentThreadHeight(this._commentThreadWidget.value!.getDimensions().height); return; } - if (this._commentThreadWidget) { + if (this._commentThreadWidget.value) { if (!info) { this._commentThreadDisposables.clear(); this._commentThreadWidget.dispose(); - this._commentThreadWidget = null; this.currentElement.commentHeight = 0; return; } - if (this._commentThreadWidget.commentThread === info.thread) { - this.currentElement.commentHeight = this._calculateCommentThreadHeight(this._commentThreadWidget.getDimensions().height); + if (this._commentThreadWidget.value.commentThread === info.thread) { + this.currentElement.commentHeight = this._calculateCommentThreadHeight(this._commentThreadWidget.value.getDimensions().height); return; } - await this._commentThreadWidget.updateCommentThread(info.thread); - this.currentElement.commentHeight = this._calculateCommentThreadHeight(this._commentThreadWidget.getDimensions().height); + await this._commentThreadWidget.value.updateCommentThread(info.thread); + this.currentElement.commentHeight = this._calculateCommentThreadHeight(this._commentThreadWidget.value.getDimensions().height); } } @@ -151,7 +149,7 @@ export class CellComments extends CellContentPart { private _applyTheme() { const theme = this.themeService.getColorTheme(); const fontInfo = this.notebookEditor.getLayoutInfo().fontInfo; - this._commentThreadWidget?.applyTheme(theme, fontInfo); + this._commentThreadWidget.value?.applyTheme(theme, fontInfo); } override didRenderCell(element: ICellViewModel): void { @@ -164,13 +162,13 @@ export class CellComments extends CellContentPart { } override prepareLayout(): void { - if (this.currentElement?.cellKind === CellKind.Code && this._commentThreadWidget) { - this.currentElement.commentHeight = this._calculateCommentThreadHeight(this._commentThreadWidget.getDimensions().height); + if (this.currentElement?.cellKind === CellKind.Code && this._commentThreadWidget.value) { + this.currentElement.commentHeight = this._calculateCommentThreadHeight(this._commentThreadWidget.value.getDimensions().height); } } override updateInternalLayoutNow(element: ICellViewModel): void { - if (this.currentElement?.cellKind === CellKind.Code && this._commentThreadWidget) { + if (this.currentElement?.cellKind === CellKind.Code && this._commentThreadWidget.value) { const layoutInfo = (element as CodeCellViewModel).layoutInfo; this.container.style.top = `${layoutInfo.outputContainerOffset + layoutInfo.outputTotalHeight}px`; } diff --git a/test/automation/package.json b/test/automation/package.json index b9dbbec4bb81a..8172250a9a397 100644 --- a/test/automation/package.json +++ b/test/automation/package.json @@ -1,6 +1,6 @@ { "name": "vscode-automation", - "version": "1.71.0", + "version": "1.91.0", "description": "VS Code UI automation driver", "author": { "name": "Microsoft Corporation" @@ -33,4 +33,4 @@ "npm-run-all": "^4.1.5", "watch": "^1.0.2" } -} +} \ No newline at end of file