-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 => { | ||
|
@@ -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 | ||
.filter(e => e.id.indexOf('vscode') === -1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this should ne |
||
.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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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")), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about having a short label - |
||
instantiationService.createInstance(DisableForWorkspaceAction, localize('disableForWorkspaceAction.label', "Disable (Workspace)")), | ||
instantiationService.createInstance(DisableGloballyAction, localize('disableAlwaysAction.label', "Disable (Always)")) | ||
], | ||
|
@@ -394,6 +395,48 @@ export class ManageExtensionAction extends Action { | |
} | ||
} | ||
|
||
export class AddToWorkspaceRecommendationsAction extends Action implements IExtensionAction { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
); | ||
return action.run() | ||
.then(() => this.extensionsWorkbenchService.addToWorkspaceRecommendations(this.extension)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'; | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,27 @@ export class ExtensionTipsService implements IExtensionTipsService { | |
}, err => []); | ||
} | ||
|
||
addToWorkspaceRecommendations(extensionId: string): TPromise<void> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
There was a problem hiding this comment.
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?