Skip to content

Commit

Permalink
Replace instanceof ThemeIcon with an is method (#10012)
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew authored and RomanNikitenko committed Sep 16, 2021
1 parent 585967a commit b1a3e73
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/plugin-ext/src/plugin/quick-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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; });
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/plugin/tree/tree-views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class TreeViewExtImpl<T> 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(<PluginIconPath | undefined>iconPath, this.plugin);
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b1a3e73

Please sign in to comment.