-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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: allow ➡️ to add chat context in background #213078
Merged
+37
−17
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,12 @@ import { Registry } from 'vs/platform/registry/common/platform'; | |
export interface IQuickAccessProviderRunOptions { | ||
readonly from?: string; | ||
readonly placeholder?: string; | ||
/** | ||
* A handler to invoke when an item is accepted for | ||
* this particular showing of the quick access. | ||
* @param item The item that was accepted. | ||
*/ | ||
readonly handleAccept?: (item: IQuickPickItem) => void; | ||
} | ||
|
||
/** | ||
|
@@ -54,7 +60,7 @@ export interface IQuickAccessOptions { | |
/** | ||
* Provider specific options for this particular showing of the | ||
* quick access. | ||
*/ | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These got misaligned |
||
readonly providerOptions?: IQuickAccessProviderRunOptions; | ||
|
||
/** | ||
|
@@ -65,7 +71,7 @@ export interface IQuickAccessOptions { | |
|
||
/** | ||
* A placeholder to use for this particular showing of the quick access. | ||
*/ | ||
*/ | ||
readonly placeholder?: string; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ import { localize, localize2 } from 'vs/nls'; | |
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions'; | ||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; | ||
import { AnythingQuickAccessProviderRunOptions } from 'vs/platform/quickinput/common/quickAccess'; | ||
import { IQuickInputService, QuickPickItem } from 'vs/platform/quickinput/common/quickInput'; | ||
import { IQuickInputService, IQuickPickItem, QuickPickItem } from 'vs/platform/quickinput/common/quickInput'; | ||
import { CHAT_CATEGORY } from 'vs/workbench/contrib/chat/browser/actions/chatActions'; | ||
import { IChatWidget, IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat'; | ||
import { SelectAndInsertFileAction } from 'vs/workbench/contrib/chat/browser/contrib/chatDynamicVariables'; | ||
|
@@ -56,10 +56,26 @@ class AttachContextAction extends Action2 { | |
}); | ||
} | ||
|
||
private _attachContext(widget: IChatWidget, ...picks: IQuickPickItem[]) { | ||
widget?.attachContext(...picks.map((p) => ({ | ||
fullName: p.label, | ||
icon: 'icon' in p && ThemeIcon.isThemeIcon(p.icon) ? p.icon : undefined, | ||
name: 'name' in p && typeof p.name === 'string' ? p.name : p.label, | ||
value: 'resource' in p && URI.isUri(p.resource) ? p.resource : undefined, | ||
id: 'id' in p && typeof p.id === 'string' ? p.id : | ||
'resource' in p && URI.isUri(p.resource) ? `${SelectAndInsertFileAction.Name}:${p.resource.toString()}` : '' | ||
}))); | ||
} | ||
|
||
override async run(accessor: ServicesAccessor, ...args: any[]): Promise<void> { | ||
const quickInputService = accessor.get(IQuickInputService); | ||
const chatVariablesService = accessor.get(IChatVariablesService); | ||
const widgetService = accessor.get(IChatWidgetService); | ||
const context: { widget?: IChatWidget } | undefined = args[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could |
||
const widget = context?.widget ?? widgetService.lastFocusedWidget; | ||
if (!widget) { | ||
return; | ||
} | ||
|
||
const quickPickItems: (QuickPickItem & { name?: string; icon?: ThemeIcon })[] = []; | ||
for (const variable of chatVariablesService.getVariables()) { | ||
|
@@ -72,10 +88,13 @@ class AttachContextAction extends Action2 { | |
quickPickItems.push(SelectAndInsertFileAction.Item, { type: 'separator' }); | ||
} | ||
|
||
const picks = await quickInputService.quickAccess.pick('', { | ||
quickInputService.quickAccess.show('', { | ||
enabledProviderPrefixes: [AnythingQuickAccessProvider.PREFIX], | ||
placeholder: localize('chatContext.attach.placeholder', 'Search attachments'), | ||
providerOptions: <AnythingQuickAccessProviderRunOptions>{ | ||
handleAccept: (item: IQuickPickItem) => { | ||
this._attachContext(widget, item); | ||
}, | ||
additionPicks: quickPickItems, | ||
includeSymbols: false, | ||
filter: (item) => { | ||
|
@@ -87,18 +106,5 @@ class AttachContextAction extends Action2 { | |
} | ||
}); | ||
|
||
if (picks?.length) { | ||
const context: { widget?: IChatWidget } | undefined = args[0]; | ||
|
||
const widget = context?.widget ?? widgetService.lastFocusedWidget; | ||
widget?.attachContext(...picks.map((p) => ({ | ||
fullName: p.label, | ||
icon: 'icon' in p && ThemeIcon.isThemeIcon(p.icon) ? p.icon : undefined, | ||
name: 'name' in p && typeof p.name === 'string' ? p.name : p.label, | ||
value: 'resource' in p && URI.isUri(p.resource) ? p.resource : undefined, | ||
id: 'id' in p && typeof p.id === 'string' ? p.id : | ||
'resource' in p && URI.isUri(p.resource) ? `${SelectAndInsertFileAction.Name}:${p.resource.toString()}` : '' | ||
}))); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you use the 'accept' callback on the item to do the same thing? I don't follow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the consumer of the quick access from chat context action land, we don't control the items in the picker, they are populated from the anything quick access in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could overwrite the
accept
handler for all items in the anything quick access layer, but this feels more explicit