Skip to content
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
5 changes: 5 additions & 0 deletions src/@types/vscode.proposed.chatContextProvider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ declare module 'vscode' {
* The value of the context item. Can be omitted when returned from one of the `provide` methods if the provider supports `resolveChatContext`.
*/
value?: string;
/**
* An optional command that is executed when the context item is clicked.
* The original context item will be passed as an argument to the command.
*/
command?: Command;
}

export interface ChatContextProvider<T extends ChatContextItem = ChatContextItem> {
Expand Down
8 changes: 7 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import { chooseItem } from './github/quickPicks';
import { RepositoriesManager } from './github/repositoriesManager';
import { codespacesPrLink, getIssuesUrl, getPullsUrl, isInCodespaces, ISSUE_OR_URL_EXPRESSION, parseIssueExpressionOutput, vscodeDevPrLink } from './github/utils';
import { OverviewContext } from './github/views';
import { IssueChatContextItem } from './lm/issueContextProvider';
import { PRChatContextItem } from './lm/pullRequestContextProvider';
import { isNotificationTreeItem, NotificationTreeItem } from './notifications/notificationItem';
import { NotificationsManager } from './notifications/notificationsManager';
import { PullRequestsTreeDataProvider } from './view/prsTreeDataProvider';
Expand Down Expand Up @@ -895,7 +897,7 @@ export function registerCommands(
}),
);

async function openDescriptionCommand(argument: RepositoryChangesNode | PRNode | IssueModel | CrossChatSessionWithPR | undefined) {
async function openDescriptionCommand(argument: RepositoryChangesNode | PRNode | IssueModel | CrossChatSessionWithPR | PRChatContextItem | IssueChatContextItem | undefined) {
let issueModel: IssueModel | undefined;
if (!argument) {
const activePullRequests: PullRequestModel[] = reposManager.folderManagers
Expand All @@ -919,6 +921,10 @@ export function registerCommands(
number: argument.pullRequestDetails.number,
preventDefaultContextMenuItems: true,
}))?.pr;
} else if (PRChatContextItem.is(argument)) {
issueModel = argument.pr;
} else if (IssueChatContextItem.is(argument)) {
issueModel = argument.issue;
} else {
issueModel = argument;
}
Expand Down
12 changes: 11 additions & 1 deletion src/lm/issueContextProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ import { RepositoriesManager } from '../github/repositoriesManager';
import { getIssueNumberLabel } from '../github/utils';
import { IssueQueryResult, StateManager } from '../issues/stateManager';

interface IssueChatContextItem extends vscode.ChatContextItem {
export interface IssueChatContextItem extends vscode.ChatContextItem {
issue: IssueModel;
}

export namespace IssueChatContextItem {
export function is(item: unknown): item is IssueChatContextItem {
return (item as IssueChatContextItem).issue !== undefined;
}
}

export class IssueContextProvider implements vscode.ChatContextProvider {
constructor(private readonly _stateManager: StateManager,
private readonly _reposManager: RepositoriesManager
Expand Down Expand Up @@ -66,6 +72,10 @@ export class IssueContextProvider implements vscode.ChatContextProvider {
label: `#${issue.number} ${issue.title}`,
modelDescription: 'The GitHub issue the user is viewing.',
issue,
command: {
command: 'issue.openDescription',
title: vscode.l10n.t('Open Issue')
}
};
}

Expand Down
12 changes: 11 additions & 1 deletion src/lm/pullRequestContextProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ import { PullRequestOverviewPanel } from '../github/pullRequestOverview';
import { RepositoriesManager } from '../github/repositoriesManager';
import { PrsTreeModel } from '../view/prsTreeModel';

interface PRChatContextItem extends vscode.ChatContextItem {
export interface PRChatContextItem extends vscode.ChatContextItem {
pr?: PullRequestModel;
}

export namespace PRChatContextItem {
export function is(item: unknown): item is PRChatContextItem {
return (item as PRChatContextItem).pr !== undefined;
}
}

export class PullRequestContextProvider extends Disposable implements vscode.ChatContextProvider {
private readonly _onDidChangeWorkspaceChatContext = new vscode.EventEmitter<void>();
readonly onDidChangeWorkspaceChatContext = this._onDidChangeWorkspaceChatContext.event;
Expand Down Expand Up @@ -112,6 +118,10 @@ Active pull request (may not be the same as open pull request): ${folderManager.
label: `#${pr.number} ${pr.title}`,
modelDescription: 'The GitHub pull request the user is viewing.',
pr,
command: {
command: 'pr.openDescription',
title: vscode.l10n.t('Open Pull Request')
}
};
}

Expand Down
Loading