From 9b99d8bf876e3cc863714d0b2135e6918648feb6 Mon Sep 17 00:00:00 2001 From: Mark Sujew Date: Tue, 31 Aug 2021 14:15:29 +0000 Subject: [PATCH] Replace `instanceof ThemeIcon` with an `is` method --- packages/plugin-ext/src/plugin/quick-open.ts | 4 ++-- packages/plugin-ext/src/plugin/tree/tree-views.ts | 2 +- packages/plugin-ext/src/plugin/types-impl.ts | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/plugin-ext/src/plugin/quick-open.ts b/packages/plugin-ext/src/plugin/quick-open.ts index 3e339e447e629..8a91373630d6e 100644 --- a/packages/plugin-ext/src/plugin/quick-open.ts +++ b/packages/plugin-ext/src/plugin/quick-open.ts @@ -41,7 +41,7 @@ export function isPromiseCanceledError(error: any): boolean { } export function getIconUris(iconPath: theia.QuickInputButton['iconPath']): { dark: URI, light: URI } | { id: string } { - if (iconPath instanceof ThemeIcon) { + if (ThemeIcon.is(iconPath)) { return { id: iconPath.id }; } const dark = getDarkIconUri(iconPath as URI | { light: URI; dark: URI; }); @@ -439,7 +439,7 @@ export class QuickInputExt implements QuickInput { const relativePath = path.relative(packagePath, normalizedPath); return PluginPackage.toPluginUrl(this.plugin.rawModel, relativePath); }; - if ('id' in iconPath || iconPath instanceof ThemeIcon) { + if (ThemeIcon.is(iconPath)) { return iconPath; } else if (typeof iconPath === 'string' || iconPath instanceof monaco.Uri) { return URI.parse(toUrl(iconPath)); diff --git a/packages/plugin-ext/src/plugin/tree/tree-views.ts b/packages/plugin-ext/src/plugin/tree/tree-views.ts index 0009270d34340..6d7957d2fd3e4 100644 --- a/packages/plugin-ext/src/plugin/tree/tree-views.ts +++ b/packages/plugin-ext/src/plugin/tree/tree-views.ts @@ -369,7 +369,7 @@ class TreeViewExtImpl implements Disposable { const { iconPath } = treeItem; if (typeof iconPath === 'string' && iconPath.indexOf('fa-') !== -1) { icon = iconPath; - } else if (iconPath instanceof ThemeIcon) { + } else if (ThemeIcon.is(iconPath)) { themeIconId = iconPath.id; } else { iconUrl = PluginIconPath.toUrl(iconPath, this.plugin); diff --git a/packages/plugin-ext/src/plugin/types-impl.ts b/packages/plugin-ext/src/plugin/types-impl.ts index 8b99e33f181b3..f15792f7ae1d7 100644 --- a/packages/plugin-ext/src/plugin/types-impl.ts +++ b/packages/plugin-ext/src/plugin/types-impl.ts @@ -702,6 +702,12 @@ export class ThemeIcon { } +export namespace ThemeIcon { + export function is(item: unknown): item is ThemeIcon { + return typeof item === 'object' && !!item && 'id' in item; + } +} + export enum TextEditorRevealType { Default = 0, InCenter = 1,