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

vsx-registry: display incompatible extensions #10424

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 5 additions & 0 deletions packages/vsx-registry/src/browser/style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
min-height: calc(var(--theia-content-line-height)*3)
}

.theia-vsx-extension.incompatible {
opacity: 0.6;
cursor: default;
}

.theia-vsx-extensions-search-bar {
padding: var(--theia-ui-padding) var(--theia-scrollbar-width) var(--theia-ui-padding) 18px /* expansion toggle padding of tree elements in result list */;
display: flex;
Expand Down
52 changes: 52 additions & 0 deletions packages/vsx-registry/src/browser/vsx-extension-preferences.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/********************************************************************************
* Copyright (C) 2021 Ericsson and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { interfaces } from '@theia/core/shared/inversify';
import { createPreferenceProxy, PreferenceProxy, PreferenceService, PreferenceContribution, PreferenceSchema } from '@theia/core/lib/browser';
import { nls } from '@theia/core';

export const VSXExtensionConfigSchema: PreferenceSchema = {
'type': 'object',
properties: {
'extensions.displayIncompatible': {
type: 'boolean',
description: nls.localize('theia/vsx-registry/displayIncompatible', 'Controls whether to display incompatible extensions when searching.'),
default: true
}
}
};

export interface VSXExtensionConfiguration {
'extensions.displayIncompatible': boolean;
}

export const VSXExtensionPreferenceContribution = Symbol('VSXExtensionPreferenceContribution');
export const VSXExtensionPreferences = Symbol('VSXExtensionPreferences');
export type VSXExtensionPreferences = PreferenceProxy<VSXExtensionConfiguration>;

export function createVSXExtensionPreferences(preferences: PreferenceService, schema: PreferenceSchema = VSXExtensionConfigSchema): VSXExtensionPreferences {
return createPreferenceProxy(preferences, schema);
}

export function bindVSXExtensionPreferences(bind: interfaces.Bind): void {
bind(VSXExtensionPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
const contribution = ctx.container.get<PreferenceContribution>(VSXExtensionPreferenceContribution);
return createVSXExtensionPreferences(preferences, contribution.schema);
}).inSingletonScope();
bind(VSXExtensionPreferenceContribution).toConstantValue({ schema: VSXExtensionConfigSchema });
bind(PreferenceContribution).toService(VSXExtensionPreferenceContribution);
}
39 changes: 28 additions & 11 deletions packages/vsx-registry/src/browser/vsx-extension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { ProgressService } from '@theia/core/lib/common/progress-service';
import { Endpoint } from '@theia/core/lib/browser/endpoint';
import { VSXEnvironment } from '../common/vsx-environment';
import { VSXExtensionsSearchModel } from './vsx-extensions-search-model';
import { MenuPath } from '@theia/core/lib/common';
import { MenuPath, nls } from '@theia/core/lib/common';
import { codicon, ContextMenuRenderer, TooltipService } from '@theia/core/lib/browser';
import { VSXExtensionNamespaceAccess, VSXUser } from '@theia/ovsx-client/lib/ovsx-types';

Expand Down Expand Up @@ -144,6 +144,11 @@ export class VSXExtension implements VSXExtensionData, TreeElement {
return type === PluginType.System;
}

get compatible(): boolean {
// An extension is not compatible if it has no compatible version.
return !!this.version;
}

update(data: Partial<VSXExtensionData>): void {
for (const key of VSXExtensionData.KEYS) {
if (key in data) {
Expand Down Expand Up @@ -260,7 +265,10 @@ export class VSXExtension implements VSXExtensionData, TreeElement {
}

get tooltip(): string {
let md = `__${this.displayName}__ ${this.version}\n\n${this.description}\n_____\n\nPublisher: ${this.publisher}`;
const version = this.version !== undefined
? this.version
: nls.localize('theia/vsx-registry/noCompatibleVersion', 'No Compatible Version');
let md = `__${this.displayName}__ ${version}\n\n${this.description}\n_____\n\nPublisher: ${this.publisher}`;

if (this.license) {
md += ` \rLicense: ${this.license}`;
Expand Down Expand Up @@ -384,21 +392,27 @@ export abstract class AbstractVSXExtensionComponent extends React.Component<Abst

protected renderAction(): React.ReactNode {
const extension = this.props.extension;
const { builtin, busy, installed } = extension;
const { builtin, busy, installed, compatible } = extension;
if (builtin) {
return <div className="codicon codicon-settings-gear action" onClick={this.manage}></div>;
}
if (busy) {
if (installed) {
return <button className="theia-button action theia-mod-disabled">Uninstalling</button>;
return <button className="theia-button action theia-mod-disabled">{nls.localizeByDefault('Uninstalling')}</button>;
}
return <button className="theia-button action prominent theia-mod-disabled">Installing</button>;
return <button className="theia-button action prominent theia-mod-disabled">{nls.localizeByDefault('Installing')}</button>;
}
if (installed) {
return <div><button className="theia-button action" onClick={this.uninstall}>Uninstall</button>
<div className="codicon codicon-settings-gear action" onClick={this.manage}></div></div>;
return (
<div>
<button className="theia-button action" onClick={this.uninstall}>{nls.localizeByDefault('Uninstall')}</button>
<div className="codicon codicon-settings-gear action" onClick={this.manage}></div>
</div>
);
}
if (compatible) {
return <button className="theia-button prominent action" onClick={this.install}>{nls.localizeByDefault('Install')}</button>;
}
return <button className="theia-button prominent action" onClick={this.install}>Install</button>;
vince-fugnitto marked this conversation as resolved.
Show resolved Hide resolved
}

}
Expand All @@ -414,16 +428,19 @@ const downloadCompactFormatter = new Intl.NumberFormat(undefined, { notation: 'c

export class VSXExtensionComponent extends AbstractVSXExtensionComponent {
render(): React.ReactNode {
const { iconUrl, publisher, displayName, description, version, downloadCount, averageRating, tooltipId, tooltip } = this.props.extension;
const { iconUrl, publisher, displayName, description, version, downloadCount, averageRating, tooltipId, tooltip, compatible } = this.props.extension;
const extensionVersion = version !== undefined
? version
: nls.localize('theia/vsx-registry/noCompatibleVersion', 'No Compatible Version');

return <div className='theia-vsx-extension noselect' data-for={tooltipId} data-tip={tooltip}>
return <div className={`theia-vsx-extension noselect ${compatible ? '' : 'incompatible'}`} data-for={tooltipId} data-tip={tooltip}>
{iconUrl ?
<img className='theia-vsx-extension-icon' src={iconUrl} /> :
<div className='theia-vsx-extension-icon placeholder' />}
<div className='theia-vsx-extension-content'>
<div className='title'>
<div className='noWrapInfo'>
<span className='name'>{displayName}</span> <span className='version'>{version}</span>
<span className='name'>{displayName}</span> <span className='version'>{extensionVersion}</span>
</div>
<div className='stat'>
{!!downloadCount && <span className='download-count'><i className={codicon('cloud-download')} />{downloadCompactFormatter.format(downloadCount)}</span>}
Expand Down
8 changes: 6 additions & 2 deletions packages/vsx-registry/src/browser/vsx-extensions-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { RecommendedExtensions } from './recommended-extensions/recommended-exte
import URI from '@theia/core/lib/common/uri';
import { VSXResponseError, VSXSearchParam } from '@theia/ovsx-client/lib/ovsx-types';
import { OVSXClientProvider } from '../common/ovsx-client-provider';
import { VSXExtensionPreferences } from './vsx-extension-preferences';

@injectable()
export class VSXExtensionsModel {
Expand All @@ -56,6 +57,9 @@ export class VSXExtensionsModel {
@inject(WorkspaceService)
protected readonly workspaceService: WorkspaceService;

@inject(VSXExtensionPreferences)
protected vsxPreferences: VSXExtensionPreferences;

@inject(VSXExtensionsSearchModel)
readonly search: VSXExtensionsSearchModel;

Expand Down Expand Up @@ -175,7 +179,7 @@ export class VSXExtensionsModel {
for (const data of result.extensions) {
const id = data.namespace.toLowerCase() + '.' + data.name.toLowerCase();
const extension = client.getLatestCompatibleVersion(data);
if (!extension) {
if (!extension && this.vsxPreferences.get('extensions.displayIncompatible') === false) {
continue;
}
this.setExtension(id).update(Object.assign(data, {
Expand All @@ -184,7 +188,7 @@ export class VSXExtensionsModel {
iconUrl: data.files.icon,
readmeUrl: data.files.readme,
licenseUrl: data.files.license,
version: extension.version
version: extension?.version
}));
searchResult.add(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { bindExtensionPreferences } from './recommended-extensions/recommended-e
import { bindPreferenceProviderOverrides } from './recommended-extensions/preference-provider-overrides';
import { OVSXClientProvider, createOVSXClient } from '../common/ovsx-client-provider';
import { VSXEnvironment, VSX_ENVIRONMENT_PATH } from '../common/vsx-environment';
import { bindVSXExtensionPreferences } from './vsx-extension-preferences';

export default new ContainerModule((bind, unbind) => {
bind<OVSXClientProvider>(OVSXClientProvider).toDynamicValue(ctx => {
Expand Down Expand Up @@ -105,4 +106,6 @@ export default new ContainerModule((bind, unbind) => {

bindExtensionPreferences(bind);
bindPreferenceProviderOverrides(bind, unbind);

bindVSXExtensionPreferences(bind);
});