Skip to content

Commit 7caf8b6

Browse files
authored
Fix duplicate chat participant issues (microsoft#208954)
The suggest item command can be run after the editor text is inserted, so make sure that the correct `lastSelectedAgent` is always used.
1 parent cac2dcf commit 7caf8b6

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export interface IChatWidget {
116116
readonly onDidChangeViewModel: Event<void>;
117117
readonly onDidAcceptInput: Event<void>;
118118
readonly onDidSubmitAgent: Event<{ agent: IChatAgentData; slashCommand?: IChatAgentCommand }>;
119+
readonly onDidChangeParsedInput: Event<void>;
119120
readonly location: ChatAgentLocation;
120121
readonly viewContext: IChatWidgetViewContext;
121122
readonly viewModel: IChatViewModel | undefined;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ export class ChatWidget extends Disposable implements IChatWidget {
9797
private _onDidAcceptInput = this._register(new Emitter<void>());
9898
readonly onDidAcceptInput = this._onDidAcceptInput.event;
9999

100+
private _onDidChangeParsedInput = this._register(new Emitter<void>());
101+
readonly onDidChangeParsedInput = this._onDidChangeParsedInput.event;
102+
100103
private _onDidChangeHeight = this._register(new Emitter<number>());
101104
readonly onDidChangeHeight = this._onDidChangeHeight.event;
102105

@@ -225,7 +228,9 @@ export class ChatWidget extends Disposable implements IChatWidget {
225228

226229
private _lastSelectedAgent: IChatAgentData | undefined;
227230
set lastSelectedAgent(agent: IChatAgentData | undefined) {
231+
this.parsedChatRequest = undefined;
228232
this._lastSelectedAgent = agent;
233+
this._onDidChangeParsedInput.fire();
229234
}
230235

231236
get lastSelectedAgent(): IChatAgentData | undefined {

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class InputEditorDecorations extends Disposable {
6666

6767
this.updateInputEditorDecorations();
6868
this._register(this.widget.inputEditor.onDidChangeModelContent(() => this.updateInputEditorDecorations()));
69+
this._register(this.widget.onDidChangeParsedInput(() => this.updateInputEditorDecorations()));
6970
this._register(this.widget.onDidChangeViewModel(() => {
7071
this.registerViewModelListeners();
7172
this.previouslyUsedAgents.clear();
@@ -211,7 +212,9 @@ class InputEditorDecorations extends Disposable {
211212

212213
const textDecorations: IDecorationOptions[] | undefined = [];
213214
if (agentPart) {
214-
const agentHover = `(${agentPart.agent.name}) ${agentPart.agent.description}`;
215+
const isDupe = !!this.chatAgentService.getAgents().find(other => other.name === agentPart.agent.name && other.id !== agentPart.agent.id);
216+
const id = isDupe ? `(${agentPart.agent.id}) ` : '';
217+
const agentHover = `${id}${agentPart.agent.description}`;
215218
textDecorations.push({ range: agentPart.editorRange, hoverMessage: new MarkdownString(agentHover) });
216219
if (agentSubcommandPart) {
217220
textDecorations.push({ range: agentSubcommandPart.editorRange, hoverMessage: new MarkdownString(agentSubcommandPart.command.description) });
@@ -456,7 +459,8 @@ class AgentCompletions extends Disposable {
456459
insertText: `${agentLabel} `,
457460
range: new Range(1, 1, 1, 1),
458461
kind: CompletionItemKind.Text,
459-
sortText: `${chatSubcommandLeader}${agent.name}`,
462+
sortText: `${chatSubcommandLeader}${agent.id}`,
463+
command: { id: AssignSelectedAgentAction.ID, title: AssignSelectedAgentAction.ID, arguments: [{ agent, widget } satisfies AssignSelectedAgentActionArgs] },
460464
};
461465
});
462466

@@ -473,7 +477,8 @@ class AgentCompletions extends Disposable {
473477
detail: `(${agentLabel}) ${c.description ?? ''}`,
474478
range: new Range(1, 1, 1, 1),
475479
kind: CompletionItemKind.Text, // The icons are disabled here anyway
476-
sortText: `${chatSubcommandLeader}${agent.name}${c.name}`,
480+
sortText: `${chatSubcommandLeader}${agent.id}${c.name}`,
481+
command: { id: AssignSelectedAgentAction.ID, title: AssignSelectedAgentAction.ID, arguments: [{ agent, widget } satisfies AssignSelectedAgentActionArgs] },
477482
} satisfies CompletionItem;
478483
})))
479484
};

0 commit comments

Comments
 (0)