Skip to content

Commit 04ed915

Browse files
authored
Merge pull request microsoft#100955 from microsoft/aeschli/exe-recommendation-show-info
exe recommendations: show exension info
2 parents c864113 + 672a53f commit 04ed915

2 files changed

Lines changed: 48 additions & 7 deletions

File tree

src/vs/workbench/contrib/extensions/browser/extensionRecommendations.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import { INotificationService, Severity } from 'vs/platform/notification/common/
88
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
99
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1010
import { localize } from 'vs/nls';
11-
import { InstallRecommendedExtensionAction, ShowRecommendedExtensionsAction } from 'vs/workbench/contrib/extensions/browser/extensionsActions';
11+
import { InstallRecommendedExtensionAction, ShowRecommendedExtensionAction } from 'vs/workbench/contrib/extensions/browser/extensionsActions';
1212
import { ExtensionRecommendationSource, IExtensionRecommendationReson } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
1313
import { IExtensionsConfiguration, ConfigurationKey } from 'vs/workbench/contrib/extensions/common/extensions';
1414
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
1515
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
1616
import { IStorageKeysSyncRegistryService } from 'vs/platform/userDataSync/common/storageKeys';
17+
import { IAction } from 'vs/base/common/actions';
1718

1819
type ExtensionRecommendationsNotificationClassification = {
1920
userReaction: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
@@ -56,22 +57,27 @@ export abstract class ExtensionRecommendations extends Disposable {
5657
return this._activationPromise;
5758
}
5859

60+
private runAction(action: IAction) {
61+
try {
62+
action.run();
63+
} finally {
64+
action.dispose();
65+
}
66+
}
67+
5968
protected promptImportantExtensionInstallNotification(extensionId: string, message: string): void {
6069
this.notificationService.prompt(Severity.Info, message,
6170
[{
6271
label: localize('install', 'Install'),
6372
run: () => {
6473
this.telemetryService.publicLog2<{ userReaction: string, extensionId: string }, ExtensionRecommendationsNotificationClassification>('extensionRecommendations:popup', { userReaction: 'install', extensionId });
65-
this.instantiationService.createInstance(InstallRecommendedExtensionAction, extensionId).run();
74+
this.runAction(this.instantiationService.createInstance(InstallRecommendedExtensionAction, extensionId));
6675
}
6776
}, {
68-
label: localize('showRecommendations', "Show Recommendations"),
77+
label: localize('moreInformation', "More Information"),
6978
run: () => {
7079
this.telemetryService.publicLog2<{ userReaction: string, extensionId: string }, ExtensionRecommendationsNotificationClassification>('extensionRecommendations:popup', { userReaction: 'show', extensionId });
71-
72-
const recommendationsAction = this.instantiationService.createInstance(ShowRecommendedExtensionsAction, ShowRecommendedExtensionsAction.ID, localize('showRecommendations', "Show Recommendations"));
73-
recommendationsAction.run();
74-
recommendationsAction.dispose();
80+
this.runAction(this.instantiationService.createInstance(ShowRecommendedExtensionAction, extensionId));
7581
}
7682
}, {
7783
label: choiceNever,

src/vs/workbench/contrib/extensions/browser/extensionsActions.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,40 @@ export class InstallWorkspaceRecommendedExtensionsAction extends Action {
18271827
}
18281828
}
18291829

1830+
export class ShowRecommendedExtensionAction extends Action {
1831+
1832+
static readonly ID = 'workbench.extensions.action.showRecommendedExtension';
1833+
static readonly LABEL = localize('showRecommendedExtension', "Show Recommended Extension");
1834+
1835+
private extensionId: string;
1836+
1837+
constructor(
1838+
extensionId: string,
1839+
@IViewletService private readonly viewletService: IViewletService,
1840+
@IExtensionsWorkbenchService private readonly extensionWorkbenchService: IExtensionsWorkbenchService,
1841+
) {
1842+
super(InstallRecommendedExtensionAction.ID, InstallRecommendedExtensionAction.LABEL, undefined, false);
1843+
this.extensionId = extensionId;
1844+
}
1845+
1846+
run(): Promise<any> {
1847+
return this.viewletService.openViewlet(VIEWLET_ID, true)
1848+
.then(viewlet => viewlet?.getViewPaneContainer() as IExtensionsViewPaneContainer)
1849+
.then(viewlet => {
1850+
viewlet.search(`@id:${this.extensionId}`);
1851+
viewlet.focus();
1852+
return this.extensionWorkbenchService.queryGallery({ names: [this.extensionId], source: 'install-recommendation', pageSize: 1 }, CancellationToken.None)
1853+
.then(pager => {
1854+
if (pager && pager.firstPage && pager.firstPage.length) {
1855+
const extension = pager.firstPage[0];
1856+
return this.extensionWorkbenchService.open(extension);
1857+
}
1858+
return null;
1859+
});
1860+
});
1861+
}
1862+
}
1863+
18301864
export class InstallRecommendedExtensionAction extends Action {
18311865

18321866
static readonly ID = 'workbench.extensions.action.installRecommendedExtension';
@@ -1855,6 +1889,7 @@ export class InstallRecommendedExtensionAction extends Action {
18551889
if (pager && pager.firstPage && pager.firstPage.length) {
18561890
const extension = pager.firstPage[0];
18571891
return this.extensionWorkbenchService.install(extension)
1892+
.then(() => this.extensionWorkbenchService.open(extension))
18581893
.then(() => null, err => {
18591894
console.error(err);
18601895
return promptDownloadManually(extension.gallery, localize('failedToInstall', "Failed to install \'{0}\'.", extension.identifier.id), err, this.instantiationService);

0 commit comments

Comments
 (0)