Fix duplicate chat participant issues (#208954)

The suggest item command can be run after the editor text is inserted, so make sure that the correct `lastSelectedAgent` is always used.
This commit is contained in:
Rob Lourens 2024-03-27 20:04:01 -03:00 committed by GitHub
parent cac2dcf41e
commit 7caf8b6cfe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 3 deletions

View file

@ -116,6 +116,7 @@ export interface IChatWidget {
readonly onDidChangeViewModel: Event<void>;
readonly onDidAcceptInput: Event<void>;
readonly onDidSubmitAgent: Event<{ agent: IChatAgentData; slashCommand?: IChatAgentCommand }>;
readonly onDidChangeParsedInput: Event<void>;
readonly location: ChatAgentLocation;
readonly viewContext: IChatWidgetViewContext;
readonly viewModel: IChatViewModel | undefined;

View file

@ -97,6 +97,9 @@ export class ChatWidget extends Disposable implements IChatWidget {
private _onDidAcceptInput = this._register(new Emitter<void>());
readonly onDidAcceptInput = this._onDidAcceptInput.event;
private _onDidChangeParsedInput = this._register(new Emitter<void>());
readonly onDidChangeParsedInput = this._onDidChangeParsedInput.event;
private _onDidChangeHeight = this._register(new Emitter<number>());
readonly onDidChangeHeight = this._onDidChangeHeight.event;
@ -225,7 +228,9 @@ export class ChatWidget extends Disposable implements IChatWidget {
private _lastSelectedAgent: IChatAgentData | undefined;
set lastSelectedAgent(agent: IChatAgentData | undefined) {
this.parsedChatRequest = undefined;
this._lastSelectedAgent = agent;
this._onDidChangeParsedInput.fire();
}
get lastSelectedAgent(): IChatAgentData | undefined {

View file

@ -66,6 +66,7 @@ class InputEditorDecorations extends Disposable {
this.updateInputEditorDecorations();
this._register(this.widget.inputEditor.onDidChangeModelContent(() => this.updateInputEditorDecorations()));
this._register(this.widget.onDidChangeParsedInput(() => this.updateInputEditorDecorations()));
this._register(this.widget.onDidChangeViewModel(() => {
this.registerViewModelListeners();
this.previouslyUsedAgents.clear();
@ -211,7 +212,9 @@ class InputEditorDecorations extends Disposable {
const textDecorations: IDecorationOptions[] | undefined = [];
if (agentPart) {
const agentHover = `(${agentPart.agent.name}) ${agentPart.agent.description}`;
const isDupe = !!this.chatAgentService.getAgents().find(other => other.name === agentPart.agent.name && other.id !== agentPart.agent.id);
const id = isDupe ? `(${agentPart.agent.id}) ` : '';
const agentHover = `${id}${agentPart.agent.description}`;
textDecorations.push({ range: agentPart.editorRange, hoverMessage: new MarkdownString(agentHover) });
if (agentSubcommandPart) {
textDecorations.push({ range: agentSubcommandPart.editorRange, hoverMessage: new MarkdownString(agentSubcommandPart.command.description) });
@ -456,7 +459,8 @@ class AgentCompletions extends Disposable {
insertText: `${agentLabel} `,
range: new Range(1, 1, 1, 1),
kind: CompletionItemKind.Text,
sortText: `${chatSubcommandLeader}${agent.name}`,
sortText: `${chatSubcommandLeader}${agent.id}`,
command: { id: AssignSelectedAgentAction.ID, title: AssignSelectedAgentAction.ID, arguments: [{ agent, widget } satisfies AssignSelectedAgentActionArgs] },
};
});
@ -473,7 +477,8 @@ class AgentCompletions extends Disposable {
detail: `(${agentLabel}) ${c.description ?? ''}`,
range: new Range(1, 1, 1, 1),
kind: CompletionItemKind.Text, // The icons are disabled here anyway
sortText: `${chatSubcommandLeader}${agent.name}${c.name}`,
sortText: `${chatSubcommandLeader}${agent.id}${c.name}`,
command: { id: AssignSelectedAgentAction.ID, title: AssignSelectedAgentAction.ID, arguments: [{ agent, widget } satisfies AssignSelectedAgentActionArgs] },
} satisfies CompletionItem;
})))
};