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

Better UX for recommended extensions #26089

Closed
wants to merge 2 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
21 changes: 19 additions & 2 deletions extensions/configuration-editing/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export function activate(context): void {
//settings.json suggestions
context.subscriptions.push(registerSettingsCompletions());

//extensions.json suggestions
context.subscriptions.push(registerExtensionsCompletions());

// launch.json decorations
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(editor => updateLaunchJsonDecorations(editor), null, context.subscriptions));
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(event => {
Expand Down Expand Up @@ -61,11 +64,25 @@ function registerSettingsCompletions(): vscode.Disposable {
});
}

function newSimpleCompletionItem(text: string, range: vscode.Range, description?: string): vscode.CompletionItem {
function registerExtensionsCompletions(): vscode.Disposable {
return vscode.languages.registerCompletionItemProvider({ pattern: '**/extensions.json' }, {
provideCompletionItems(document, position, token) {
const location = getLocation(document.getText(), document.offsetAt(position));
const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
if (location.path[0] === 'recommendations') {
return vscode.extensions.all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest if there are no installed extensions?

.filter(e => e.id.indexOf('vscode') === -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this should ne e.id.startsWith('vscode.')?

.map(e => newSimpleCompletionItem(e.id, range, undefined, '"' + e.id + '"'));
}
}
});
}

function newSimpleCompletionItem(text: string, range: vscode.Range, description?: string, insertText?: string): vscode.CompletionItem {
const item = new vscode.CompletionItem(text);
item.kind = vscode.CompletionItemKind.Value;
item.detail = description;
item.insertText = text;
item.insertText = insertText || text;
item.range = range;

return item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export interface IExtensionTipsService {
_serviceBrand: any;
getRecommendations(): string[];
getWorkspaceRecommendations(): TPromise<string[]>;
addToWorkspaceRecommendations(extensionId: string): TPromise<void>;
getKeymapRecommendations(): string[];
getKeywordsForExtension(extension: string): string[];
getRecommendationsForExtension(extension: string): string[];
Expand Down
67 changes: 67 additions & 0 deletions src/vs/workbench/parts/extensions/browser/extensionsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ export class ManageExtensionAction extends Action {
instantiationService.createInstance(EnableGloballyAction, localize('enableAlwaysAction.label', "Enable (Always)"))
],
[
instantiationService.createInstance(AddToWorkspaceRecommendationsAction, localize('addToWorkspaceRecommendationsAction.label', "Add to Workspace Recommendations")),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about having a short label - Recommend (Workspace) and Unrecommend (Workspace). Not sure Workspace word is necessary since a user can recommend only to Workspace, but having it makes it complete.

instantiationService.createInstance(DisableForWorkspaceAction, localize('disableForWorkspaceAction.label', "Disable (Workspace)")),
instantiationService.createInstance(DisableGloballyAction, localize('disableAlwaysAction.label', "Disable (Always)"))
],
Expand Down Expand Up @@ -394,6 +395,48 @@ export class ManageExtensionAction extends Action {
}
}

export class AddToWorkspaceRecommendationsAction extends Action implements IExtensionAction {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is an action to add an extension to recommended list, there should also be a counter action to remove it from recommended list


static ID = 'extensions.addToWorkspaceRecommendationsAction';
static LABEL = localize('addToWorkspaceRecommendationsAction', "Workspace");

private disposables: IDisposable[] = [];

private _extension: IExtension;
get extension(): IExtension { return this._extension; }
set extension(extension: IExtension) { this._extension = extension; this.update(); }

constructor(label: string,
@IWorkspaceContextService private workspaceContextService: IWorkspaceContextService,
@IExtensionsWorkbenchService private extensionsWorkbenchService: IExtensionsWorkbenchService,
@IExtensionEnablementService private extensionEnablementService: IExtensionEnablementService,
@IInstantiationService private instantiationService: IInstantiationService
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove those services which are not used

) {
super(AddToWorkspaceRecommendationsAction.ID, label);

this.disposables.push(this.extensionsWorkbenchService.onChange(() => this.update()));
this.update();
}

private update(): void {
this.enabled = !!this.extension;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enablement should also depends on if it is already recommended or not and also if there is a workspace or not

}

run(): TPromise<any> {
const action = <Action>this.instantiationService.createInstance(
ConfigureWorkspaceRecommendedExtensionsAction,
ConfigureWorkspaceRecommendedExtensionsAction.ID,
ConfigureWorkspaceRecommendedExtensionsAction.LABEL
Copy link
Member

@sandy081 sandy081 May 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Check for the case when there is no workspace.
  • Also why do we need to show the extensions file if we can just add the recommendation silently in the background.

);
return action.run()
.then(() => this.extensionsWorkbenchService.addToWorkspaceRecommendations(this.extension));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not call the ExtensionTip service directly to add a recommendation?

}

dispose(): void {
super.dispose();
this.disposables = dispose(this.disposables);
}
}
export class EnableForWorkspaceAction extends Action implements IExtensionAction {

static ID = 'extensions.enableForWorkspace';
Expand Down Expand Up @@ -1020,6 +1063,30 @@ export class ShowWorkspaceRecommendedExtensionsAction extends Action {
}
}

export class InstallWorkspaceRecommendedExtensionsAction extends Action {

static ID = 'workbench.extensions.action.installWorkspaceRecommendedExtensions';
static LABEL = localize('installWorkspaceRecommendedExtensions', "Install Workspace Recommended Extensions");

constructor(
id: string,
label: string,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IViewletService private viewletService: IViewletService,
@IExtensionsWorkbenchService private extensionsWorkbenchService: IExtensionsWorkbenchService
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused services

) {
super(id, label, null, contextService.hasWorkspace());
}

run(): TPromise<void> {
return this.extensionsWorkbenchService.installAllWorkspaceRecommendations();
}

protected isEnabled(): boolean {
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not be enabled if there are no recommendations or all recommended extensions are already installed and also if there is a workspace or not

}
}

export class ShowRecommendedKeymapExtensionsAction extends Action {

static ID = 'workbench.extensions.action.showRecommendedKeymapExtensions';
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/parts/extensions/common/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export interface IExtensionsWorkbenchService {
loadDependencies(extension: IExtension): TPromise<IExtensionDependencies>;
open(extension: IExtension, sideByside?: boolean): TPromise<any>;
checkForUpdates(): TPromise<void>;
addToWorkspaceRecommendations(extension: IExtension): TPromise<void>;
installAllWorkspaceRecommendations(): TPromise<void>;
}

export const ConfigurationKey = 'extensions';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const ExtensionsConfigurationSchema: IJSONSchema = {
description: localize('app.extensions.json.recommendations', "List of extensions recommendations. The identifier of an extension is always '${publisher}.${name}'. For example: 'vscode.csharp'."),
items: {
type: 'string',
defaultSnippets: [{ label: 'Example', body: 'vscode.csharp' }],
defaultSnippets: [],
pattern: EXTENSION_IDENTIFIER_PATTERN,
errorMessage: localize('app.extension.identifier.errorMessage', "Expected format '${publisher}.${name}'. Example: 'vscode.csharp'.")
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,27 @@ export class ExtensionTipsService implements IExtensionTipsService {
}, err => []);
}

addToWorkspaceRecommendations(extensionId: string): TPromise<void> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Check if extensionId is valid or not
  • I would rather use workbench model service and json edit utility to update. This will retain the existing formatting options of the file. Refer ConfigurationEditingService that edits configuration files programatically.

if (!this.contextService.hasWorkspace()) {
return TPromise.as(void 0);
}
const resource = this.contextService.toResource(paths.join('.vscode', 'extensions.json'));
return this.fileService.resolveContent(resource).then(content => {
const extensionsContent = <IExtensionsContent>json.parse(content.value, []);
const regEx = new RegExp(EXTENSION_IDENTIFIER_PATTERN);
let recommendations = extensionsContent.recommendations || [];
recommendations = recommendations.filter((element, position) => {
return recommendations.indexOf(element) === position && regEx.test(element);
});
if (recommendations.indexOf(extensionId) === -1) {
recommendations.push(extensionId);
}
extensionsContent.recommendations = recommendations;
return this.fileService.updateContent(resource, JSON.stringify(extensionsContent, null, 2))
.then(() => recommendations);
}, err => []).then(() => void 0);
}

getRecommendations(): string[] {
return Object.keys(this._recommendations);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { VIEWLET_ID, IExtensionsWorkbenchService } from '../common/extensions';
import { ExtensionsWorkbenchService } from 'vs/workbench/parts/extensions/node/extensionsWorkbenchService';
import {
OpenExtensionsViewletAction, InstallExtensionsAction, ShowOutdatedExtensionsAction, ShowRecommendedExtensionsAction, ShowRecommendedKeymapExtensionsAction, ShowWorkspaceRecommendedExtensionsAction, ShowPopularExtensionsAction,
ShowInstalledExtensionsAction, ShowDisabledExtensionsAction, UpdateAllAction, ConfigureWorkspaceRecommendedExtensionsAction,
OpenExtensionsViewletAction, InstallExtensionsAction, ShowOutdatedExtensionsAction, ShowRecommendedExtensionsAction, ShowRecommendedKeymapExtensionsAction, ShowWorkspaceRecommendedExtensionsAction, InstallWorkspaceRecommendedExtensionsAction, ShowPopularExtensionsAction, ShowInstalledExtensionsAction, ShowDisabledExtensionsAction, UpdateAllAction, ConfigureWorkspaceRecommendedExtensionsAction,
EnableAllAction, EnableAllWorkpsaceAction, DisableAllAction, DisableAllWorkpsaceAction, CheckForUpdatesAction
} from 'vs/workbench/parts/extensions/browser/extensionsActions';
import { OpenExtensionsFolderAction, InstallVSIXAction } from 'vs/workbench/parts/extensions/electron-browser/extensionsActions';
Expand Down Expand Up @@ -118,6 +117,9 @@ actionRegistry.registerWorkbenchAction(keymapRecommendationsActionDescriptor, 'P
const workspaceRecommendationsActionDescriptor = new SyncActionDescriptor(ShowWorkspaceRecommendedExtensionsAction, ShowWorkspaceRecommendedExtensionsAction.ID, ShowWorkspaceRecommendedExtensionsAction.LABEL);
actionRegistry.registerWorkbenchAction(workspaceRecommendationsActionDescriptor, 'Extensions: Show Workspace Recommended Extensions', ExtensionsLabel);

const installWorkspaceRecommendationsActionDescriptor = new SyncActionDescriptor(InstallWorkspaceRecommendedExtensionsAction, InstallWorkspaceRecommendedExtensionsAction.ID, InstallWorkspaceRecommendedExtensionsAction.LABEL);
actionRegistry.registerWorkbenchAction(installWorkspaceRecommendationsActionDescriptor, 'Extensions: Install Workspace Recommended Extensions', ExtensionsLabel);

const popularActionDescriptor = new SyncActionDescriptor(ShowPopularExtensionsAction, ShowPopularExtensionsAction.ID, ShowPopularExtensionsAction.LABEL);
actionRegistry.registerWorkbenchAction(popularActionDescriptor, 'Extensions: Show Popular Extensions', ExtensionsLabel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { Delegate, Renderer } from 'vs/workbench/parts/extensions/browser/extensionsList';
import { IExtensionsWorkbenchService, IExtension, IExtensionsViewlet, VIEWLET_ID, ExtensionState } from '../common/extensions';
import {
ShowRecommendedExtensionsAction, ShowWorkspaceRecommendedExtensionsAction, ShowRecommendedKeymapExtensionsAction, ShowPopularExtensionsAction, ShowInstalledExtensionsAction, ShowDisabledExtensionsAction,
ShowRecommendedExtensionsAction, ShowWorkspaceRecommendedExtensionsAction, InstallWorkspaceRecommendedExtensionsAction, ShowRecommendedKeymapExtensionsAction, ShowPopularExtensionsAction, ShowInstalledExtensionsAction, ShowDisabledExtensionsAction,
ShowOutdatedExtensionsAction, ClearExtensionsInputAction, ChangeSortAction, UpdateAllAction, CheckForUpdatesAction
} from 'vs/workbench/parts/extensions/browser/extensionsActions';
import { InstallVSIXAction } from 'vs/workbench/parts/extensions/electron-browser/extensionsActions';
Expand Down Expand Up @@ -199,6 +199,7 @@ export class ExtensionsViewlet extends Viewlet implements IExtensionsViewlet {
this.instantiationService.createInstance(ShowDisabledExtensionsAction, ShowDisabledExtensionsAction.ID, ShowDisabledExtensionsAction.LABEL),
this.instantiationService.createInstance(ShowRecommendedExtensionsAction, ShowRecommendedExtensionsAction.ID, ShowRecommendedExtensionsAction.LABEL),
this.instantiationService.createInstance(ShowWorkspaceRecommendedExtensionsAction, ShowWorkspaceRecommendedExtensionsAction.ID, ShowWorkspaceRecommendedExtensionsAction.LABEL),
this.instantiationService.createInstance(InstallWorkspaceRecommendedExtensionsAction, InstallWorkspaceRecommendedExtensionsAction.ID, InstallWorkspaceRecommendedExtensionsAction.LABEL),
this.instantiationService.createInstance(ShowRecommendedKeymapExtensionsAction, ShowRecommendedKeymapExtensionsAction.ID, ShowRecommendedKeymapExtensionsAction.LABEL),
this.instantiationService.createInstance(ShowPopularExtensionsAction, ShowPopularExtensionsAction.ID, ShowPopularExtensionsAction.LABEL),
new Separator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,32 @@ export class ExtensionsWorkbenchService implements IExtensionsWorkbenchService {
});
}

addToWorkspaceRecommendations(extension: IExtension): TPromise<void> {
return this.tipsService.addToWorkspaceRecommendations(extension.id);
}

installAllWorkspaceRecommendations(): TPromise<void> {
return this.tipsService.getWorkspaceRecommendations()
.then(extensions => {
this.queryGallery({ names: extensions })
.done(result => {
if (result.total < 1) {
return;
}

const extension = result.firstPage[0];
const promises = [this.open(extension)];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry.. I did not get why do we need to open extension


if (this.local.every(local => local.id !== extension.id)) {
promises.push(this.install(extension));
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I misunderstood.. I see it is installing only one recommended extensions in the list not all.. I do not see complete result is being read to install?

TPromise.join(promises)
.done(null, error => this.onError(error));
});
});
}

dispose(): void {
this.syncDelayer.cancel();
this.disposables = dispose(this.disposables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ suite('ExtensionsActions Test', () => {
});
});

test('Test AddToWorkspaceRecommendationsAction when there is no extension', () => {
const testObject: ExtensionsActions.AddToWorkspaceRecommendationsAction = instantiationService.createInstance(ExtensionsActions.AddToWorkspaceRecommendationsAction, 'id');
assert.ok(!testObject.enabled);
});

test('Test EnableForWorkspaceAction when there is no extension', () => {
const testObject: ExtensionsActions.EnableForWorkspaceAction = instantiationService.createInstance(ExtensionsActions.EnableForWorkspaceAction, 'id');

Expand Down