Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace instanceof ThemeIcon with an is method #10012

Merged
merged 1 commit into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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