Skip to content

Commit

Permalink
Allow remote help contribution to take command
Browse files Browse the repository at this point in the history
Fixes #99661
  • Loading branch information
alexr00 committed Jun 23, 2020
1 parent e6124e3 commit 6493a67
Showing 1 changed file with 68 additions and 46 deletions.
114 changes: 68 additions & 46 deletions src/vs/workbench/contrib/remote/browser/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ const remoteHelpExtPoint = ExtensionsRegistry.registerExtensionPoint<HelpInforma
type: 'object',
properties: {
'getStarted': {
description: nls.localize('RemoteHelpInformationExtPoint.getStarted', "The url to your project's Getting Started page"),
description: nls.localize('RemoteHelpInformationExtPoint.getStarted', "The url, or a command that returns the url, to your project's Getting Started page"),
type: 'string'
},
'documentation': {
description: nls.localize('RemoteHelpInformationExtPoint.documentation', "The url to your project's documentation page"),
description: nls.localize('RemoteHelpInformationExtPoint.documentation', "The url, or a command that returns the url, to your project's documentation page"),
type: 'string'
},
'feedback': {
description: nls.localize('RemoteHelpInformationExtPoint.feedback', "The url to your project's feedback reporter"),
description: nls.localize('RemoteHelpInformationExtPoint.feedback', "The url, or a command that returns the url, to your project's feedback reporter"),
type: 'string'
},
'issues': {
description: nls.localize('RemoteHelpInformationExtPoint.issues', "The url to your project's issues list"),
description: nls.localize('RemoteHelpInformationExtPoint.issues', "The url, or a command that returns the url, to your project's issues list"),
type: 'string'
}
}
Expand Down Expand Up @@ -182,11 +182,11 @@ class HelpModel {
helpItems.push(new HelpItem(
getStartedIcon,
nls.localize('remote.help.getStarted', "Get Started"),
getStarted.map((info: HelpInformation) => ({
extensionDescription: info.extensionDescription,
url: info.getStarted!,
remoteAuthority: (typeof info.remoteName === 'string') ? [info.remoteName] : info.remoteName
})),
getStarted.map((info: HelpInformation) => (new HelpItemValue(commandService,
info.extensionDescription,
(typeof info.remoteName === 'string') ? [info.remoteName] : info.remoteName,
info.getStarted!)
)),
quickInputService,
environmentService,
openerService,
Expand All @@ -200,11 +200,11 @@ class HelpModel {
helpItems.push(new HelpItem(
documentationIcon,
nls.localize('remote.help.documentation', "Read Documentation"),
documentation.map((info: HelpInformation) => ({
extensionDescription: info.extensionDescription,
url: info.documentation!,
remoteAuthority: (typeof info.remoteName === 'string') ? [info.remoteName] : info.remoteName
})),
documentation.map((info: HelpInformation) => (new HelpItemValue(commandService,
info.extensionDescription,
(typeof info.remoteName === 'string') ? [info.remoteName] : info.remoteName,
info.documentation!)
)),
quickInputService,
environmentService,
openerService,
Expand All @@ -218,11 +218,11 @@ class HelpModel {
helpItems.push(new HelpItem(
feedbackIcon,
nls.localize('remote.help.feedback', "Provide Feedback"),
feedback.map((info: HelpInformation) => ({
extensionDescription: info.extensionDescription,
url: info.feedback!,
remoteAuthority: (typeof info.remoteName === 'string') ? [info.remoteName] : info.remoteName
})),
feedback.map((info: HelpInformation) => (new HelpItemValue(commandService,
info.extensionDescription,
(typeof info.remoteName === 'string') ? [info.remoteName] : info.remoteName,
info.feedback!)
)),
quickInputService,
environmentService,
openerService,
Expand All @@ -236,11 +236,11 @@ class HelpModel {
helpItems.push(new HelpItem(
reviewIssuesIcon,
nls.localize('remote.help.issues', "Review Issues"),
issues.map((info: HelpInformation) => ({
extensionDescription: info.extensionDescription,
url: info.issues!,
remoteAuthority: (typeof info.remoteName === 'string') ? [info.remoteName] : info.remoteName
})),
issues.map((info: HelpInformation) => (new HelpItemValue(commandService,
info.extensionDescription,
(typeof info.remoteName === 'string') ? [info.remoteName] : info.remoteName,
info.issues!)
)),
quickInputService,
environmentService,
openerService,
Expand All @@ -252,10 +252,10 @@ class HelpModel {
helpItems.push(new IssueReporterItem(
reportIssuesIcon,
nls.localize('remote.help.report', "Report Issue"),
viewModel.helpInformation.map(info => ({
extensionDescription: info.extensionDescription,
remoteAuthority: (typeof info.remoteName === 'string') ? [info.remoteName] : info.remoteName
})),
viewModel.helpInformation.map(info => (new HelpItemValue(commandService,
info.extensionDescription,
(typeof info.remoteName === 'string') ? [info.remoteName] : info.remoteName
))),
quickInputService,
environmentService,
commandService,
Expand All @@ -269,12 +269,35 @@ class HelpModel {
}
}

class HelpItemValue {
private _url: string | undefined;
constructor(private commandService: ICommandService, public extensionDescription: IExtensionDescription, public remoteAuthority: string[] | undefined, private urlOrCommand?: string) { }

get url(): Promise<string> {
return new Promise(async (resolve) => {
if (this._url === undefined) {
if (this.urlOrCommand) {
let url = URI.parse(this.urlOrCommand);
if (url.authority) {
this._url = this.urlOrCommand;
} else {
this._url = await this.commandService.executeCommand(this.urlOrCommand);
}
} else {
this._url = '';
}
}
resolve(this._url);
});
}
}

abstract class HelpItemBase implements IHelpItem {
public iconClasses: string[] = [];
constructor(
public icon: Codicon,
public label: string,
public values: { extensionDescription: IExtensionDescription, url?: string, remoteAuthority: string[] | undefined }[],
public values: HelpItemValue[],
private quickInputService: IQuickInputService,
private environmentService: IWorkbenchEnvironmentService,
private remoteExplorerService: IRemoteExplorerService
Expand All @@ -285,17 +308,16 @@ abstract class HelpItemBase implements IHelpItem {

async handleClick() {
const remoteAuthority = this.environmentService.configuration.remoteAuthority;
if (!remoteAuthority) {
return;
}
for (let i = 0; i < this.remoteExplorerService.targetType.length; i++) {
if (startsWith(remoteAuthority, this.remoteExplorerService.targetType[i])) {
for (let value of this.values) {
if (value.remoteAuthority) {
for (let authority of value.remoteAuthority) {
if (startsWith(remoteAuthority, authority)) {
await this.takeAction(value.extensionDescription, value.url);
return;
if (remoteAuthority) {
for (let i = 0; i < this.remoteExplorerService.targetType.length; i++) {
if (startsWith(remoteAuthority, this.remoteExplorerService.targetType[i])) {
for (let value of this.values) {
if (value.remoteAuthority) {
for (let authority of value.remoteAuthority) {
if (startsWith(remoteAuthority, authority)) {
await this.takeAction(value.extensionDescription, await value.url);
return;
}
}
}
}
Expand All @@ -304,21 +326,21 @@ abstract class HelpItemBase implements IHelpItem {
}

if (this.values.length > 1) {
let actions = this.values.map(value => {
let actions = await Promise.all(this.values.map(async (value) => {
return {
label: value.extensionDescription.displayName || value.extensionDescription.identifier.value,
description: value.url,
description: await value.url,
extensionDescription: value.extensionDescription
};
});
}));

const action = await this.quickInputService.pick(actions, { placeHolder: nls.localize('pickRemoteExtension', "Select url to open") });

if (action) {
await this.takeAction(action.extensionDescription, action.description);
}
} else {
await this.takeAction(this.values[0].extensionDescription, this.values[0].url);
await this.takeAction(this.values[0].extensionDescription, await this.values[0].url);
}
}

Expand All @@ -329,7 +351,7 @@ class HelpItem extends HelpItemBase {
constructor(
icon: Codicon,
label: string,
values: { extensionDescription: IExtensionDescription; url: string, remoteAuthority: string[] | undefined }[],
values: HelpItemValue[],
quickInputService: IQuickInputService,
environmentService: IWorkbenchEnvironmentService,
private openerService: IOpenerService,
Expand All @@ -347,7 +369,7 @@ class IssueReporterItem extends HelpItemBase {
constructor(
icon: Codicon,
label: string,
values: { extensionDescription: IExtensionDescription; remoteAuthority: string[] | undefined }[],
values: HelpItemValue[],
quickInputService: IQuickInputService,
environmentService: IWorkbenchEnvironmentService,
private commandService: ICommandService,
Expand Down

0 comments on commit 6493a67

Please sign in to comment.