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

feat: add top level Symbol... to Attach Context picker #213435

Merged
merged 2 commits into from
May 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ import { IChatRequestVariableEntry } from 'vs/workbench/contrib/chat/common/chat
import { ChatRequestAgentPart } from 'vs/workbench/contrib/chat/common/chatParserTypes';
import { IChatVariablesService } from 'vs/workbench/contrib/chat/common/chatVariables';
import { AnythingQuickAccessProvider } from 'vs/workbench/contrib/search/browser/anythingQuickAccess';
import { ISymbolQuickPickItem, SymbolsQuickAccessProvider } from 'vs/workbench/contrib/search/browser/symbolsQuickAccess';

export function registerChatContextActions() {
registerAction2(AttachContextAction);
}

export type IChatContextQuickPickItem = IFileQuickPickItem | IDynamicVariableQuickPickItem | IStaticVariableQuickPickItem | IGotoSymbolQuickPickItem;
export type IChatContextQuickPickItem = IFileQuickPickItem | IDynamicVariableQuickPickItem | IStaticVariableQuickPickItem | IGotoSymbolQuickPickItem | ISymbolQuickPickItem | IQuickAccessQuickPickItem;

export interface IFileQuickPickItem extends IQuickPickItem {
kind: 'file';
Expand Down Expand Up @@ -66,6 +67,15 @@ export interface IStaticVariableQuickPickItem extends IQuickPickItem {
icon?: ThemeIcon;
}

export interface IQuickAccessQuickPickItem extends IQuickPickItem {
kind: 'quickaccess';
id: string;
name: string;
value: string;

prefix: string;
}

class AttachContextAction extends Action2 {

static readonly ID = 'workbench.action.chat.attachContext';
Expand Down Expand Up @@ -124,11 +134,21 @@ class AttachContextAction extends Action2 {
// Apply the original icon with the new name
fullName: `${pick.icon ? `$(${pick.icon.id}) ` : ''}${selection}`
});
} else if (pick && typeof pick === 'object' && 'resource' in pick) {
} else if ('symbol' in pick && pick.symbol) {
// Symbol
toAttach.push({
...pick,
id: this._getFileContextId(pick.symbol.location),
value: pick.symbol.location,
fullName: pick.label,
name: pick.symbol.name,
isDynamic: true
});
} else if (pick && typeof pick === 'object' && 'resource' in pick && pick.resource) {
// #file variable
toAttach.push({
...pick,
id: this._getFileContextId(pick),
id: this._getFileContextId({ resource: pick.resource }),
value: pick.resource,
name: pick.label,
isFile: true,
Expand Down Expand Up @@ -209,22 +229,40 @@ class AttachContextAction extends Action2 {

}

quickInputService.quickAccess.show('', {
quickPickItems.push({
label: localize('chatContext.symbol', '{0} Symbol...', `$(${Codicon.symbolField.id})`),
icon: ThemeIcon.fromId(Codicon.symbolField.id),
prefix: SymbolsQuickAccessProvider.PREFIX
});

this._show(quickInputService, commandService, widget, quickPickItems);
}

private _show(quickInputService: IQuickInputService, commandService: ICommandService, widget: IChatWidget, quickPickItems: (IChatContextQuickPickItem | QuickPickItem)[], query: string = '') {
quickInputService.quickAccess.show(query, {
enabledProviderPrefixes: [
AnythingQuickAccessProvider.PREFIX,
SymbolsQuickAccessProvider.PREFIX,
AbstractGotoSymbolQuickAccessProvider.PREFIX
],
placeholder: localize('chatContext.attach.placeholder', 'Search attachments'),
providerOptions: <AnythingQuickAccessProviderRunOptions>{
handleAccept: (item: IChatContextQuickPickItem) => {
this._attachContext(widget, commandService, item);
if ('prefix' in item) {
this._show(quickInputService, commandService, widget, quickPickItems, item.prefix);
} else {
this._attachContext(widget, commandService, item);
}
},
additionPicks: quickPickItems,
includeSymbols: false,
filter: (item: IChatContextQuickPickItem) => {
// Avoid attaching the same context twice
const attachedContext = widget.getContrib<ChatContextAttachments>(ChatContextAttachments.ID)?.getContext() ?? new Set();

if ('symbol' in item && item.symbol) {
return !attachedContext.has(this._getFileContextId(item.symbol.location));
}

if (item && typeof item === 'object' && 'resource' in item && URI.isUri(item.resource)) {
return [Schemas.file, Schemas.vscodeRemote].includes(item.resource.scheme)
&& !attachedContext.has(this._getFileContextId({ resource: item.resource })); // Hack because Typescript doesn't narrow this type correctly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { IMatch } from 'vs/base/common/filters';
import { Codicon } from 'vs/base/common/codicons';
import { ThemeIcon } from 'vs/base/common/themables';

interface ISymbolQuickPickItem extends IPickerQuickAccessItem, IQuickPickItemWithResource {
export interface ISymbolQuickPickItem extends IPickerQuickAccessItem, IQuickPickItemWithResource {
score?: number;
symbol?: IWorkspaceSymbol;
}
Expand Down
Loading