From 32d935ebf4f5a7b74823d5ba6635d18a32acfa03 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 17 Dec 2020 16:14:07 -0800 Subject: [PATCH] Extract type guard --- src/vs/workbench/api/common/extHostCustomEditors.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/api/common/extHostCustomEditors.ts b/src/vs/workbench/api/common/extHostCustomEditors.ts index becd0887e19..ef4a079c22b 100644 --- a/src/vs/workbench/api/common/extHostCustomEditors.ts +++ b/src/vs/workbench/api/common/extHostCustomEditors.ts @@ -178,7 +178,7 @@ export class ExtHostCustomEditors implements extHostProtocol.ExtHostCustomEditor options: { webviewOptions?: vscode.WebviewPanelOptions, supportsMultipleEditorsPerDocument?: boolean }, ): vscode.Disposable { const disposables = new DisposableStore(); - if ('resolveCustomTextEditor' in provider) { + if (isCustomTextEditorProvider(provider)) { disposables.add(this._editorProviders.addTextProvider(viewType, extension, provider)); this._proxy.$registerTextEditorProvider(toExtensionData(extension), viewType, options.webviewOptions || {}, { supportsMove: !!provider.moveCustomTextEditor, @@ -208,7 +208,6 @@ export class ExtHostCustomEditors implements extHostProtocol.ExtHostCustomEditor })); } - async $createCustomDocument(resource: UriComponents, viewType: string, backupId: string | undefined, cancellation: CancellationToken) { const entry = this._editorProviders.get(viewType); if (!entry) { @@ -350,7 +349,6 @@ export class ExtHostCustomEditors implements extHostProtocol.ExtHostCustomEditor return backup.id; } - private getCustomDocumentEntry(viewType: string, resource: UriComponents): CustomDocumentStoreEntry { const entry = this._documents.get(viewType, URI.revive(resource)); if (!entry) { @@ -375,6 +373,9 @@ export class ExtHostCustomEditors implements extHostProtocol.ExtHostCustomEditor } } +function isCustomTextEditorProvider(provider: vscode.CustomReadonlyEditorProvider | vscode.CustomTextEditorProvider): provider is vscode.CustomTextEditorProvider { + return typeof (provider as vscode.CustomTextEditorProvider).resolveCustomTextEditor === 'function'; +} function isEditEvent(e: vscode.CustomDocumentContentChangeEvent | vscode.CustomDocumentEditEvent): e is vscode.CustomDocumentEditEvent { return typeof (e as vscode.CustomDocumentEditEvent).undo === 'function' -- GitLab