Skip to content

Commit 3132200

Browse files
authored
Merge pull request microsoft#207864 from microsoft/joh/chatWidget
Use ChatWidget and ChatModel for inline chat
2 parents 7a6ee40 + fdde488 commit 3132200

File tree

60 files changed

+1411
-1609
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1411
-1609
lines changed

src/vs/workbench/api/browser/mainThreadInlineChat.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { reviveWorkspaceEditDto } from 'vs/workbench/api/browser/mainThreadBulkE
1010
import { ExtHostContext, ExtHostInlineChatShape, MainContext, MainThreadInlineChatShape as MainThreadInlineChatShape } from 'vs/workbench/api/common/extHost.protocol';
1111
import { IExtHostContext, extHostNamedCustomer } from 'vs/workbench/services/extensions/common/extHostCustomers';
1212
import { IProgress } from 'vs/platform/progress/common/progress';
13+
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
1314

1415
@extHostNamedCustomer(MainContext.MainThreadInlineChat)
1516
export class MainThreadInlineChat implements MainThreadInlineChatShape {
@@ -31,9 +32,9 @@ export class MainThreadInlineChat implements MainThreadInlineChatShape {
3132
this._registrations.dispose();
3233
}
3334

34-
async $registerInteractiveEditorProvider(handle: number, label: string, debugName: string, supportsFeedback: boolean, supportsFollowups: boolean, supportIssueReporting: boolean): Promise<void> {
35+
async $registerInteractiveEditorProvider(handle: number, label: string, extensionId: ExtensionIdentifier, supportsFeedback: boolean, supportsFollowups: boolean, supportIssueReporting: boolean): Promise<void> {
3536
const unreg = this._inlineChatService.addProvider({
36-
debugName,
37+
extensionId,
3738
label,
3839
supportIssueReporting,
3940
prepareInlineChatSession: async (model, range, token) => {

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ export interface ExtHostChatVariablesShape {
12651265
}
12661266

12671267
export interface MainThreadInlineChatShape extends IDisposable {
1268-
$registerInteractiveEditorProvider(handle: number, label: string, debugName: string, supportsFeedback: boolean, supportsFollowups: boolean, supportsIssueReporting: boolean): Promise<void>;
1268+
$registerInteractiveEditorProvider(handle: number, label: string, extensionId: ExtensionIdentifier, supportsFeedback: boolean, supportsFollowups: boolean, supportsIssueReporting: boolean): Promise<void>;
12691269
$handleProgressChunk(requestId: string, chunk: Dto<IInlineChatProgressItem>): Promise<void>;
12701270
$unregisterInteractiveEditorProvider(handle: number): Promise<void>;
12711271
}

src/vs/workbench/api/common/extHostInlineChat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class ExtHostInteractiveEditor implements ExtHostInlineChatShape {
9696
registerProvider(extension: Readonly<IRelaxedExtensionDescription>, provider: vscode.InteractiveEditorSessionProvider, metadata?: vscode.InteractiveEditorSessionProviderMetadata): vscode.Disposable {
9797
const wrapper = new ProviderWrapper(extension, provider);
9898
this._inputProvider.set(wrapper.handle, wrapper);
99-
this._proxy.$registerInteractiveEditorProvider(wrapper.handle, metadata?.label ?? extension.displayName ?? extension.name, extension.identifier.value, typeof provider.handleInteractiveEditorResponseFeedback === 'function', typeof provider.provideFollowups === 'function', metadata?.supportReportIssue ?? false);
99+
this._proxy.$registerInteractiveEditorProvider(wrapper.handle, metadata?.label ?? extension.displayName ?? extension.name, extension.identifier, typeof provider.handleInteractiveEditorResponseFeedback === 'function', typeof provider.provideFollowups === 'function', metadata?.supportReportIssue ?? false);
100100
return toDisposable(() => {
101101
this._proxy.$unregisterInteractiveEditorProvider(wrapper.handle);
102102
this._inputProvider.delete(wrapper.handle);

src/vs/workbench/api/common/extHostTypeConverters.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,6 +2628,7 @@ export namespace ChatLocation {
26282628
case ChatAgentLocation.Notebook: return types.ChatLocation.Notebook;
26292629
case ChatAgentLocation.Terminal: return types.ChatLocation.Terminal;
26302630
case ChatAgentLocation.Panel: return types.ChatLocation.Panel;
2631+
case ChatAgentLocation.Editor: return types.ChatLocation.Editor;
26312632
}
26322633
}
26332634
}

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4327,7 +4327,8 @@ export class ChatResponseTurn implements vscode.ChatResponseTurn {
43274327
export enum ChatLocation {
43284328
Panel = 1,
43294329
Terminal = 2,
4330-
Notebook = 3
4330+
Notebook = 3,
4331+
Editor = 4,
43314332
}
43324333

43334334
export class LanguageModelChatSystemMessage {

src/vs/workbench/contrib/chat/browser/actions/chatAccessibilityHelp.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
99
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
1010
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
1111
import { IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat';
12-
import { InlineChatController } from 'vs/workbench/contrib/inlineChat/browser/inlineChatController';
1312
import { AccessibleViewType, IAccessibleViewService } from 'vs/workbench/contrib/accessibility/browser/accessibleView';
1413
import { AccessibilityVerbositySettingId, AccessibleViewProviderId } from 'vs/workbench/contrib/accessibility/browser/accessibilityConfiguration';
1514
import { AccessibleDiffViewerNext } from 'vs/editor/browser/widget/diffEditor/commands';
15+
import { INLINE_CHAT_ID } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
1616

1717
export function getAccessibilityHelpText(accessor: ServicesAccessor, type: 'panelChat' | 'inlineChat'): string {
1818
const keybindingService = accessor.get(IKeybindingService);
@@ -81,10 +81,12 @@ export async function runAccessibilityHelpAction(accessor: ServicesAccessor, edi
8181
if (type === 'panelChat' && cachedPosition) {
8282
inputEditor.setPosition(cachedPosition);
8383
inputEditor.focus();
84+
8485
} else if (type === 'inlineChat') {
85-
if (editor) {
86-
InlineChatController.get(editor)?.focus();
87-
}
86+
// TODO@jrieken find a better way for this
87+
const ctrl = <{ focus(): void } | undefined>editor?.getContribution(INLINE_CHAT_ID);
88+
ctrl?.focus();
89+
8890
}
8991
},
9092
options: { type: AccessibleViewType.Help }

src/vs/workbench/contrib/chat/browser/chat.contribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { ChatVariablesService } from 'vs/workbench/contrib/chat/browser/chatVari
4242
import { ChatWidgetService } from 'vs/workbench/contrib/chat/browser/chatWidget';
4343
import 'vs/workbench/contrib/chat/browser/contrib/chatHistoryVariables';
4444
import 'vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib';
45-
import { ChatAgentService, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
45+
import { ChatAgentLocation, ChatAgentService, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
4646
import { CONTEXT_IN_CHAT_SESSION } from 'vs/workbench/contrib/chat/common/chatContextKeys';
4747
import { IChatContributionService } from 'vs/workbench/contrib/chat/common/chatContributionService';
4848
import { ChatWelcomeMessageModel } from 'vs/workbench/contrib/chat/common/chatModel';
@@ -250,7 +250,7 @@ class ChatSlashStaticSlashCommandsContribution extends Disposable {
250250
sortText: 'z1_help',
251251
executeImmediately: true
252252
}, async (prompt, progress) => {
253-
const defaultAgent = chatAgentService.getDefaultAgent();
253+
const defaultAgent = chatAgentService.getDefaultAgent(ChatAgentLocation.Panel);
254254
const agents = chatAgentService.getAgents();
255255

256256
// Report prefix

src/vs/workbench/contrib/chat/browser/chat.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import { URI } from 'vs/base/common/uri';
99
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
1010
import { Selection } from 'vs/editor/common/core/selection';
1111
import { localize } from 'vs/nls';
12+
import { MenuId } from 'vs/platform/actions/common/actions';
1213
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
1314
import { IChatWidgetContrib } from 'vs/workbench/contrib/chat/browser/chatWidget';
1415
import { ICodeBlockActionContext } from 'vs/workbench/contrib/chat/browser/codeBlockPart';
15-
import { IChatAgentCommand, IChatAgentData } from 'vs/workbench/contrib/chat/common/chatAgents';
16+
import { ChatAgentLocation, IChatAgentCommand, IChatAgentData } from 'vs/workbench/contrib/chat/common/chatAgents';
1617
import { IParsedChatRequest } from 'vs/workbench/contrib/chat/common/chatParserTypes';
1718
import { IChatRequestViewModel, IChatResponseViewModel, IChatViewModel, IChatWelcomeMessageViewModel } from 'vs/workbench/contrib/chat/common/chatViewModel';
1819

@@ -90,6 +91,13 @@ export interface IChatWidgetViewOptions {
9091
renderInputOnTop?: boolean;
9192
renderStyle?: 'default' | 'compact';
9293
supportsFileReferences?: boolean;
94+
filter?: (item: ChatTreeItem) => boolean;
95+
editableCodeBlocks?: boolean;
96+
menus?: {
97+
executeToolbar?: MenuId;
98+
inputSideToolbar?: MenuId;
99+
telemetrySource?: string;
100+
};
93101
}
94102

95103
export interface IChatViewViewContext {
@@ -106,6 +114,7 @@ export interface IChatWidget {
106114
readonly onDidChangeViewModel: Event<void>;
107115
readonly onDidAcceptInput: Event<void>;
108116
readonly onDidSubmitAgent: Event<{ agent: IChatAgentData; slashCommand?: IChatAgentCommand }>;
117+
readonly location: ChatAgentLocation;
109118
readonly viewContext: IChatWidgetViewContext;
110119
readonly viewModel: IChatViewModel | undefined;
111120
readonly inputEditor: ICodeEditor;

src/vs/workbench/contrib/chat/browser/chatEditor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { IChatViewState, ChatWidget } from 'vs/workbench/contrib/chat/browser/ch
2121
import { IChatModel, ISerializableChatData } from 'vs/workbench/contrib/chat/common/chatModel';
2222
import { clearChatEditor } from 'vs/workbench/contrib/chat/browser/actions/chatClear';
2323
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
24+
import { ChatAgentLocation } from 'vs/workbench/contrib/chat/common/chatAgents';
2425

2526
export interface IChatEditorOptions extends IEditorOptions {
2627
target: { sessionId: string } | { providerId: string } | { data: ISerializableChatData };
@@ -59,6 +60,7 @@ export class ChatEditor extends EditorPane {
5960
this.widget = this._register(
6061
scopedInstantiationService.createInstance(
6162
ChatWidget,
63+
ChatAgentLocation.Panel,
6264
{ resource: true },
6365
{ supportsFileReferences: true },
6466
{

src/vs/workbench/contrib/chat/browser/chatFollowups.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { MarkdownString } from 'vs/base/common/htmlContent';
99
import { Disposable } from 'vs/base/common/lifecycle';
1010
import { localize } from 'vs/nls';
1111
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
12-
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
12+
import { ChatAgentLocation, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
1313
import { chatAgentLeader, chatSubcommandLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes';
1414
import { IChatFollowup } from 'vs/workbench/contrib/chat/common/chatService';
1515
import { IInlineChatFollowup } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
@@ -20,6 +20,7 @@ export class ChatFollowups<T extends IChatFollowup | IInlineChatFollowup> extend
2020
constructor(
2121
container: HTMLElement,
2222
followups: T[],
23+
private readonly location: ChatAgentLocation,
2324
private readonly options: IButtonStyles | undefined,
2425
private readonly clickHandler: (followup: T) => void,
2526
@IContextKeyService private readonly contextService: IContextKeyService,
@@ -37,13 +38,13 @@ export class ChatFollowups<T extends IChatFollowup | IInlineChatFollowup> extend
3738
return;
3839
}
3940

40-
if (!this.chatAgentService.getDefaultAgent()) {
41+
if (!this.chatAgentService.getDefaultAgent(this.location)) {
4142
// No default agent yet, which affects how followups are rendered, so can't render this yet
4243
return;
4344
}
4445

4546
let tooltipPrefix = '';
46-
if ('agentId' in followup && followup.agentId && followup.agentId !== this.chatAgentService.getDefaultAgent()?.id) {
47+
if ('agentId' in followup && followup.agentId && followup.agentId !== this.chatAgentService.getDefaultAgent(this.location)?.id) {
4748
tooltipPrefix += `${chatAgentLeader}${followup.agentId} `;
4849
if ('subCommand' in followup && followup.subCommand) {
4950
tooltipPrefix += `${chatSubcommandLeader}${followup.subCommand} `;

0 commit comments

Comments
 (0)