mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
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:
parent
cac2dcf41e
commit
7caf8b6cfe
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
})))
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue