Skip to content

Commit a2ebc3e

Browse files
Copilotalexr00
andauthored
Add command to open GitHub issue from cursor position (#8272)
* Initial plan * Initial plan for adding command to open issue from hover Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Add command to open issue from hover reference - Implemented issue.openIssueOnGitHub command in IssueFeatureRegistrar - Command gets issue reference at cursor position and opens it on GitHub - Added command to package.json with icon - Added localized string to package.nls.json Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Fix property name from stateManager to _stateManager Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 6436221 commit a2ebc3e

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,12 @@
15811581
"title": "%command.issue.openDescription.title%",
15821582
"category": "%command.issues.category%"
15831583
},
1584+
{
1585+
"command": "issue.openIssueOnGitHub",
1586+
"title": "%command.issue.openIssueOnGitHub.title%",
1587+
"category": "%command.issues.category%",
1588+
"icon": "$(globe)"
1589+
},
15841590
{
15851591
"command": "issue.createIssueFromSelection",
15861592
"title": "%command.issue.createIssueFromSelection.title%",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@
305305
"command.pr.checkoutOnCodespacesFromDescription.title": "Checkout on Codespaces",
306306
"command.pr.openSessionLogFromDescription.title": "View Session",
307307
"command.issue.openDescription.title": "View Issue Description",
308+
"command.issue.openIssueOnGitHub.title": "Open Issue on GitHub",
308309
"command.issue.copyGithubDevLink.title": "Copy github.dev Link",
309310
"command.issue.copyGithubPermalink.title": "Copy GitHub Permalink",
310311
"command.issue.copyGithubHeadLink.title": "Copy GitHub Head Link",

src/issues/issueFeatureRegistrar.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,52 @@ export class IssueFeatureRegistrar extends Disposable {
311311
return this.openIssue(issueModel);
312312
}),
313313
);
314+
this._register(
315+
vscode.commands.registerCommand('issue.openIssueOnGitHub', async () => {
316+
const editor = vscode.window.activeTextEditor;
317+
if (!editor) {
318+
vscode.window.showWarningMessage(vscode.l10n.t('No active editor. Open a file and place the cursor on an issue reference.'));
319+
return;
320+
}
321+
322+
const document = editor.document;
323+
const position = editor.selection.active;
324+
325+
const wordRange = document.getWordRangeAtPosition(position, ISSUE_OR_URL_EXPRESSION);
326+
if (!wordRange) {
327+
vscode.window.showWarningMessage(vscode.l10n.t('No issue reference found at cursor position.'));
328+
return;
329+
}
330+
331+
const word = document.getText(wordRange);
332+
const match = word.match(ISSUE_OR_URL_EXPRESSION);
333+
const parsed = parseIssueExpressionOutput(match);
334+
335+
if (!parsed) {
336+
vscode.window.showWarningMessage(vscode.l10n.t('Invalid issue reference.'));
337+
return;
338+
}
339+
340+
const folderManager = this.manager.getManagerForFile(document.uri) ?? this.manager.folderManagers[0];
341+
if (!folderManager) {
342+
vscode.window.showWarningMessage(vscode.l10n.t('No repository found for current file.'));
343+
return;
344+
}
345+
346+
const issue = await getIssue(this._stateManager, folderManager, word, parsed);
347+
if (!issue) {
348+
vscode.window.showWarningMessage(vscode.l10n.t('Unable to resolve issue.'));
349+
return;
350+
}
351+
352+
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(issue.html_url));
353+
354+
/* __GDPR__
355+
"issue.openOnGitHub" : {}
356+
*/
357+
this.telemetry.sendTelemetryEvent('issue.openOnGitHub');
358+
}),
359+
);
314360
this._register(
315361
vscode.commands.registerCommand(
316362
'issue.startWorking',

0 commit comments

Comments
 (0)