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

Update GHPRI link sharing contributions #4584

Merged
merged 17 commits into from
Mar 8, 2023
Merged
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
131 changes: 119 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"enabledApiProposals": [
"tokenInformation",
"contribShareMenu",
"contribEditorLineNumberMenu",
"treeItemCheckbox",
"contribCommentPeekContext",
"contribCommentThreadAdditionalMenu",
Expand All @@ -24,7 +25,7 @@
"version": "0.58.0",
"publisher": "GitHub",
"engines": {
"vscode": "^1.76.0"
"vscode": "^1.77.0-insider"
},
"categories": [
"Other"
Expand Down Expand Up @@ -928,6 +929,21 @@
"title": "%command.pr.copyVscodeDevPrLink.title%",
"category": "%command.issues.category%"
},
{
"command": "issue.copyGithubDevLinkWithoutRange",
"title": "%command.issue.copyGithubDevLink.title%",
"category": "%command.issues.category%"
},
{
"command": "issue.copyGithubDevLinkFile",
"title": "%command.issue.copyGithubDevLink.title%",
"category": "%command.issues.category%"
},
{
"command": "issue.copyGithubDevLink",
"title": "%command.issue.copyGithubDevLink.title%",
"category": "%command.issues.category%"
},
{
"command": "issue.copyGithubPermalink",
"title": "%command.issue.copyGithubPermalink.title%",
Expand All @@ -938,11 +954,26 @@
"title": "%command.issue.copyGithubHeadLink.title%",
"category": "%command.issues.category%"
},
{
"command": "issue.copyGithubPermalinkWithoutRange",
"title": "%command.issue.copyGithubPermalink.title%",
"category": "%command.issues.category%"
},
{
"command": "issue.copyGithubHeadLinkWithoutRange",
"title": "%command.issue.copyGithubHeadLink.title%",
"category": "%command.issues.category%"
},
{
"command": "issue.copyMarkdownGithubPermalink",
"title": "%command.issue.copyMarkdownGithubPermalink.title%",
"category": "%command.issues.category%"
},
{
"command": "issue.copyMarkdownGithubPermalinkWithoutRange",
"title": "%command.issue.copyMarkdownGithubPermalink.title%",
"category": "%command.issues.category%"
},
{
"command": "issue.openGithubPermalink",
"title": "%command.issue.openGithubPermalink.title%",
Expand Down Expand Up @@ -1347,7 +1378,7 @@
},
{
"command": "pr.copyVscodeDevPrLink",
"when": "github:inReviewMode"
"when": "github:inReviewMode && remoteName != codespaces && embedderIdentifier != github.dev"
},
{
"command": "pr.goToNextDiffInPr",
Expand Down Expand Up @@ -1469,6 +1500,30 @@
"command": "issue.goToLinkedCode",
"when": "false"
},
{
"command": "issue.copyGithubDevLinkWithoutRange",
"when": "false"
},
{
"command": "issue.copyGithubDevLinkFile",
"when": "false"
},
{
"command": "issue.copyGithubDevLink",
"when": "false"
},
{
"command": "issue.copyGithubPermalinkWithoutRange",
"when": "false"
},
{
"command": "issue.copyMarkdownGithubPermalinkWithoutRange",
"when": "false"
},
{
"command": "issue.copyGithubHeadLinkWithoutRange",
"when": "false"
},
{
"command": "pr.refreshActivePullRequest",
"when": "false"
Expand Down Expand Up @@ -1953,6 +2008,11 @@
"command": "issue.copyGithubHeadLink",
"when": "github:hasGitHubRemotes",
"group": "1_githubPullRequests@2"
},
{
"command": "issue.copyGithubDevLink",
"when": "github:hasGitHubRemotes && remoteName == codespaces || github:hasGitHubRemotes && embedderIdentifier == github.dev",
"group": "0_vscode@0"
}
],
"file/share": [
Expand All @@ -1963,7 +2023,7 @@
},
{
"command": "pr.copyVscodeDevPrLink",
"when": "github:hasGitHubRemotes && github:inReviewMode",
"when": "github:hasGitHubRemotes && github:inReviewMode && remoteName != codespaces && embedderIdentifier != github.dev",
"group": "1_githubPullRequests@1"
},
{
Expand All @@ -1975,30 +2035,77 @@
"command": "issue.copyGithubHeadLink",
"when": "github:hasGitHubRemotes",
"group": "1_githubPullRequests@3"
},
{
"command": "issue.copyGithubDevLinkFile",
"when": "github:hasGitHubRemotes && remoteName == codespaces || github:hasGitHubRemotes && embedderIdentifier == github.dev",
"group": "0_vscode@0"
}
],
"editor/title/context": [
"editor/lineNumber/context": [
{
"command": "issue.copyGithubPermalink",
"when": "github:hasGitHubRemotes",
"group": "1_cutcopypaste@10"
"when": "github:hasGitHubRemotes && activeEditor == workbench.editors.files.textFileEditor && config.editor.lineNumbers == on",
"group": "1_cutcopypaste@3"
},
{
"command": "issue.copyMarkdownGithubPermalink",
"when": "github:hasGitHubRemotes && activeEditor == workbench.editors.files.textFileEditor && config.editor.lineNumbers == on",
"group": "1_cutcopypaste@4"
},
{
"command": "issue.copyGithubHeadLink",
"when": "github:hasGitHubRemotes && activeEditor == workbench.editors.files.textFileEditor && config.editor.lineNumbers == on",
Copy link
Member

Choose a reason for hiding this comment

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

Are all the config.editor.lineNumbers == on conditions needed? I would expect this to be controlled by VS Code core.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure it would make sense for core to handle hiding these commands, since the editor/lineNumber/context menu could also eventually include other extension-contributed items that we'd want to show regardless of line number enablement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This behavior also isn't final since I've already gotten feedback that it's unexpected that these commands would go away based on line numbers being toggled off to reduce visual noise.

"group": "1_cutcopypaste@5"
},
{
"command": "issue.copyGithubDevLink",
"when": "github:hasGitHubRemotes && remoteName == codespaces || github:hasGitHubRemotes && embedderIdentifier == github.dev",
"group": "1_cutcopypaste@0"
Copy link
Member

Choose a reason for hiding this comment

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

nit: since this one is 1_cutcopypaste@0 I would put it first.

}
],
"editor/title/context/share": [
{
"command": "issue.copyGithubPermalinkWithoutRange",
"when": "github:hasGitHubRemotes",
"group": "1_githubPullRequests@10"
},
{
"command": "issue.copyMarkdownGithubPermalinkWithoutRange",
"when": "github:hasGitHubRemotes",
"group": "1_cutcopypaste@11"
"group": "1_githubPullRequests@11"
},
{
"command": "issue.copyGithubHeadLinkWithoutRange",
"when": "github:hasGitHubRemotes",
"group": "1_githubPullRequests@12"
},
{
"command": "issue.copyGithubDevLinkWithoutRange",
"when": "github:hasGitHubRemotes && remoteName == codespaces || github:hasGitHubRemotes && embedderIdentifier == github.dev",
"group": "0_vscode@0"
}
],
"explorer/context": [
"explorer/context/share": [
{
"command": "issue.copyGithubPermalink",
"command": "issue.copyGithubPermalinkWithoutRange",
"when": "github:hasGitHubRemotes",
"group": "5_cutcopypaste@10"
"group": "5_githubPulLRequests@10"
},
{
"command": "issue.copyGithubHeadLink",
"command": "issue.copyMarkdownGithubPermalinkWithoutRange",
"when": "github:hasGitHubRemotes",
"group": "5_githubPulLRequests@11"
},
{
"command": "issue.copyGithubHeadLinkWithoutRange",
"when": "github:hasGitHubRemotes",
"group": "5_cutcopypaste@11"
"group": "5_githubPulLRequests@12"
},
{
"command": "issue.copyGithubDevLinkWithoutRange",
"when": "github:hasGitHubRemotes && remoteName == codespaces || github:hasGitHubRemotes && embedderIdentifier == github.dev",
"group": "0_vscode@0"
}
],
"menuBar/edit/copy": [
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
"command.issue.createIssueFromSelection.title": "Create Issue From Selection",
"command.issue.createIssueFromClipboard.title": "Create Issue From Clipboard",
"command.pr.copyVscodeDevPrLink.title": "Copy vscode.dev Pull Request Link",
"command.issue.copyGithubDevLink.title": "Copy github.dev Link",
"command.issue.copyGithubPermalink.title": "Copy GitHub Permalink",
"command.issue.copyGithubHeadLink.title": "Copy GitHub Head Link",
"command.issue.copyMarkdownGithubPermalink.title": "Copy GitHub Permalink as Markdown",
Expand Down
113 changes: 95 additions & 18 deletions src/issues/issueFeatureRegistrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
createGithubPermalink,
getIssue,
ISSUES_CONFIGURATION,
LinkContext,
NewIssue,
PermalinkInfo,
pushAndCreatePR,
Expand Down Expand Up @@ -119,12 +120,12 @@ export class IssueFeatureRegistrar implements vscode.Disposable {
this.context.subscriptions.push(
vscode.commands.registerCommand(
'issue.copyGithubPermalink',
(fileUri: any) => {
(context: LinkContext) => {
/* __GDPR__
"issue.copyGithubPermalink" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyGithubPermalink');
return this.copyPermalink(this.manager, fileUri instanceof vscode.Uri ? fileUri : undefined);
return this.copyPermalink(this.manager, context);
},
this,
),
Expand All @@ -142,15 +143,93 @@ export class IssueFeatureRegistrar implements vscode.Disposable {
this,
),
);
this.context.subscriptions.push(
vscode.commands.registerCommand(
'issue.copyGithubPermalinkWithoutRange',
(context: LinkContext) => {
/* __GDPR__
"issue.copyGithubPermalinkWithoutRange" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyGithubPermalinkWithoutRange');
return this.copyPermalink(this.manager, context, false);
},
this,
),
);
this.context.subscriptions.push(
vscode.commands.registerCommand(
'issue.copyGithubHeadLinkWithoutRange',
(fileUri: any) => {
/* __GDPR__
"issue.copyGithubHeadLinkWithoutRange" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyGithubHeadLinkWithoutRange');
return this.copyHeadLink(fileUri, false);
},
this,
),
);
this.context.subscriptions.push(
vscode.commands.registerCommand(
'issue.copyGithubDevLinkWithoutRange',
(context: LinkContext) => {
/* __GDPR__
"issue.copyGithubDevLinkWithoutRange" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyGithubDevLinkWithoutRange');
return this.copyPermalink(this.manager, context, false, true);
},
this,
),
);
this.context.subscriptions.push(
vscode.commands.registerCommand(
'issue.copyGithubDevLink',
(context: LinkContext) => {
/* __GDPR__
"issue.copyGithubDevLink" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyGithubDevLink');
return this.copyPermalink(this.manager, context, true, true);
},
this,
),
);
this.context.subscriptions.push(
vscode.commands.registerCommand(
'issue.copyGithubDevLinkFile',
(context: LinkContext) => {
/* __GDPR__
"issue.copyGithubDevLinkFile" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyGithubDevLinkFile');
return this.copyPermalink(this.manager, context, true, true, false);
},
this,
),
);
this.context.subscriptions.push(
vscode.commands.registerCommand(
'issue.copyMarkdownGithubPermalink',
() => {
(context: LinkContext) => {
/* __GDPR__
"issue.copyMarkdownGithubPermalink" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyMarkdownGithubPermalink');
return this.copyMarkdownPermalink(this.manager);
return this.copyMarkdownPermalink(this.manager, context);
},
this,
),
);
this.context.subscriptions.push(
vscode.commands.registerCommand(
'issue.copyMarkdownGithubPermalinkWithoutRange',
(context: LinkContext) => {
/* __GDPR__
"issue.copyMarkdownGithubPermalinkWithoutRange" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyMarkdownGithubPermalinkWithoutRange');
return this.copyMarkdownPermalink(this.manager, context, false);
},
this,
),
Expand Down Expand Up @@ -1117,16 +1196,16 @@ ${body ?? ''}\n
return false;
}

private async getPermalinkWithError(repositoriesManager: RepositoriesManager, fileUri?: vscode.Uri): Promise<PermalinkInfo> {
const link = await createGithubPermalink(repositoriesManager, this.gitAPI, undefined, fileUri);
private async getPermalinkWithError(repositoriesManager: RepositoriesManager, context?: LinkContext, includeRange?: boolean, includeFile?: boolean): Promise<PermalinkInfo> {
const link = await createGithubPermalink(repositoriesManager, this.gitAPI, undefined, context, includeRange, includeFile);
if (link.error) {
vscode.window.showWarningMessage(vscode.l10n.t('Unable to create a GitHub permalink for the selection. {0}', link.error));
}
return link;
}

private async getHeadLinkWithError(fileUri?: vscode.Uri): Promise<PermalinkInfo> {
const link = await createGitHubLink(this.manager, fileUri);
private async getHeadLinkWithError(context?: vscode.Uri, includeRange?: boolean): Promise<PermalinkInfo> {
const link = await createGitHubLink(this.manager, context, includeRange);
if (link.error) {
vscode.window.showWarningMessage(vscode.l10n.t('Unable to create a GitHub link for the selection. {0}', link.error));
}
Expand All @@ -1150,19 +1229,17 @@ ${body ?? ''}\n
return linkUri.with({ authority, path: linkPath }).toString();
}

async copyPermalink(repositoriesManager: RepositoriesManager, fileUri?: vscode.Uri) {
const link = await this.getPermalinkWithError(repositoriesManager, fileUri);
async copyPermalink(repositoriesManager: RepositoriesManager, context?: LinkContext, includeRange = true, contextualizeLink = false, includeFile = true) {
const link = await this.getPermalinkWithError(repositoriesManager, context, includeRange, includeFile);
if (link.permalink) {
return vscode.env.clipboard.writeText(
link.originalFile ? (await this.getContextualizedLink(link.originalFile, link.permalink)) : link.permalink);
return vscode.env.clipboard.writeText(contextualizeLink && link.originalFile ? await this.getContextualizedLink(link.originalFile, link.permalink) : link.permalink);
}
}

async copyHeadLink(fileUri?: vscode.Uri) {
const link = await this.getHeadLinkWithError(fileUri);
async copyHeadLink(fileUri?: vscode.Uri, includeRange = true) {
const link = await this.getHeadLinkWithError(fileUri, includeRange);
if (link.permalink) {
return vscode.env.clipboard.writeText(
link.originalFile ? (await this.getContextualizedLink(link.originalFile, link.permalink)) : link.permalink);
return vscode.env.clipboard.writeText(link.permalink);
}
}

Expand All @@ -1188,8 +1265,8 @@ ${body ?? ''}\n
return undefined;
}

async copyMarkdownPermalink(repositoriesManager: RepositoriesManager) {
const link = await this.getPermalinkWithError(repositoriesManager);
async copyMarkdownPermalink(repositoriesManager: RepositoriesManager, context: LinkContext, includeRange = true) {
const link = await this.getPermalinkWithError(repositoriesManager, context, includeRange);
const selection = this.getMarkdownLinkText();
if (link.permalink && selection) {
return vscode.env.clipboard.writeText(`[${selection.trim()}](${link.permalink})`);
Expand Down
Loading