Skip to content

Commit 32d935e

Browse files
committed
Extract type guard
1 parent 186792c commit 32d935e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/vs/workbench/api/common/extHostCustomEditors.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class ExtHostCustomEditors implements extHostProtocol.ExtHostCustomEditor
178178
options: { webviewOptions?: vscode.WebviewPanelOptions, supportsMultipleEditorsPerDocument?: boolean },
179179
): vscode.Disposable {
180180
const disposables = new DisposableStore();
181-
if ('resolveCustomTextEditor' in provider) {
181+
if (isCustomTextEditorProvider(provider)) {
182182
disposables.add(this._editorProviders.addTextProvider(viewType, extension, provider));
183183
this._proxy.$registerTextEditorProvider(toExtensionData(extension), viewType, options.webviewOptions || {}, {
184184
supportsMove: !!provider.moveCustomTextEditor,
@@ -208,7 +208,6 @@ export class ExtHostCustomEditors implements extHostProtocol.ExtHostCustomEditor
208208
}));
209209
}
210210

211-
212211
async $createCustomDocument(resource: UriComponents, viewType: string, backupId: string | undefined, cancellation: CancellationToken) {
213212
const entry = this._editorProviders.get(viewType);
214213
if (!entry) {
@@ -350,7 +349,6 @@ export class ExtHostCustomEditors implements extHostProtocol.ExtHostCustomEditor
350349
return backup.id;
351350
}
352351

353-
354352
private getCustomDocumentEntry(viewType: string, resource: UriComponents): CustomDocumentStoreEntry {
355353
const entry = this._documents.get(viewType, URI.revive(resource));
356354
if (!entry) {
@@ -375,6 +373,9 @@ export class ExtHostCustomEditors implements extHostProtocol.ExtHostCustomEditor
375373
}
376374
}
377375

376+
function isCustomTextEditorProvider(provider: vscode.CustomReadonlyEditorProvider<vscode.CustomDocument> | vscode.CustomTextEditorProvider): provider is vscode.CustomTextEditorProvider {
377+
return typeof (provider as vscode.CustomTextEditorProvider).resolveCustomTextEditor === 'function';
378+
}
378379

379380
function isEditEvent(e: vscode.CustomDocumentContentChangeEvent | vscode.CustomDocumentEditEvent): e is vscode.CustomDocumentEditEvent {
380381
return typeof (e as vscode.CustomDocumentEditEvent).undo === 'function'

0 commit comments

Comments
 (0)