From 2ceeaeb6814f4fbc75c43aaea150de29a307e3db Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 1 Feb 2021 17:06:51 +0100 Subject: [PATCH] hide proxy from TextEditorDecorationType --- .../src/singlefolder-tests/rpc.test.ts | 1 - .../workbench/api/common/extHostTextEditor.ts | 19 ++++++++++--------- .../api/common/extHostTextEditors.ts | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/rpc.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/rpc.test.ts index 68707e42df2..7d60f3e8771 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/rpc.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/rpc.test.ts @@ -20,7 +20,6 @@ suite('vscode', function () { }); test('no rpc, createTextEditorDecorationType(...)', function () { - this.skip(); const item = vscode.window.createTextEditorDecorationType({}); dispo.push(item); assertNoRpcFromEntry([item, 'TextEditorDecorationType']); diff --git a/src/vs/workbench/api/common/extHostTextEditor.ts b/src/vs/workbench/api/common/extHostTextEditor.ts index 6e2a3e4e324..f3dff81c544 100644 --- a/src/vs/workbench/api/common/extHostTextEditor.ts +++ b/src/vs/workbench/api/common/extHostTextEditor.ts @@ -16,22 +16,23 @@ import type * as vscode from 'vscode'; import { ILogService } from 'vs/platform/log/common/log'; import { Lazy } from 'vs/base/common/lazy'; -export class TextEditorDecorationType implements vscode.TextEditorDecorationType { +export class TextEditorDecorationType { private static readonly _Keys = new IdGenerator('TextEditorDecorationType'); - private _proxy: MainThreadTextEditorsShape; - public key: string; + readonly value: vscode.TextEditorDecorationType; constructor(proxy: MainThreadTextEditorsShape, options: vscode.DecorationRenderOptions) { - this.key = TextEditorDecorationType._Keys.nextId(); - this._proxy = proxy; - this._proxy.$registerTextEditorDecorationType(this.key, TypeConverters.DecorationRenderOptions.from(options)); + const key = TextEditorDecorationType._Keys.nextId(); + proxy.$registerTextEditorDecorationType(key, TypeConverters.DecorationRenderOptions.from(options)); + this.value = Object.freeze({ + key, + dispose() { + proxy.$removeTextEditorDecorationType(key); + } + }); } - public dispose(): void { - this._proxy.$removeTextEditorDecorationType(this.key); - } } export interface ITextEditOperation { diff --git a/src/vs/workbench/api/common/extHostTextEditors.ts b/src/vs/workbench/api/common/extHostTextEditors.ts index b01d113fe2b..dc8bd7bd910 100644 --- a/src/vs/workbench/api/common/extHostTextEditors.ts +++ b/src/vs/workbench/api/common/extHostTextEditors.ts @@ -92,7 +92,7 @@ export class ExtHostEditors implements ExtHostEditorsShape { } createTextEditorDecorationType(options: vscode.DecorationRenderOptions): vscode.TextEditorDecorationType { - return new TextEditorDecorationType(this._proxy, options); + return new TextEditorDecorationType(this._proxy, options).value; } // --- called from main thread