Skip to content

Commit 437a79c

Browse files
authored
Render publisher with dupe chat participant names (microsoft#209983)
* Render publisher with dupe chat participant names * Use publisher for suggest as well
1 parent 52dc2fd commit 437a79c

21 files changed

+60
-19
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { ChatRequestAgentPart } from 'vs/workbench/contrib/chat/common/chatParse
2626
import { ChatRequestParser } from 'vs/workbench/contrib/chat/common/chatRequestParser';
2727
import { IChatFollowup, IChatProgress, IChatService } from 'vs/workbench/contrib/chat/common/chatService';
2828
import { IExtHostContext, extHostNamedCustomer } from 'vs/workbench/services/extensions/common/extHostCustomers';
29+
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
2930

3031
interface AgentData {
3132
dispose: () => void;
@@ -51,6 +52,7 @@ export class MainThreadChatAgents2 extends Disposable implements MainThreadChatA
5152
@IChatWidgetService private readonly _chatWidgetService: IChatWidgetService,
5253
@IInstantiationService private readonly _instantiationService: IInstantiationService,
5354
@ILogService private readonly _logService: ILogService,
55+
@IExtensionService private readonly _extensionService: IExtensionService,
5456
) {
5557
super();
5658
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostChatAgents2);
@@ -128,12 +130,14 @@ export class MainThreadChatAgents2 extends Disposable implements MainThreadChatA
128130

129131
let disposable: IDisposable;
130132
if (!staticAgentRegistration && dynamicProps) {
133+
const extensionDescription = this._extensionService.extensions.find(e => ExtensionIdentifier.equals(e.identifier, extension));
131134
disposable = this._chatAgentService.registerDynamicAgent(
132135
{
133136
id,
134137
name: dynamicProps.name,
135138
description: dynamicProps.description,
136139
extensionId: extension,
140+
extensionPublisher: extensionDescription?.publisherDisplayName ?? extension.value,
137141
metadata: revive(metadata),
138142
slashCommands: [],
139143
locations: [ChatAgentLocation.Panel] // TODO all dynamic participants are panel only?

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Location } from 'vs/editor/common/languages';
1111
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1212
import { ILabelService } from 'vs/platform/label/common/label';
1313
import { ILogService } from 'vs/platform/log/common/log';
14+
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
1415
import { ChatRequestAgentPart, ChatRequestDynamicVariablePart, ChatRequestTextPart, IParsedChatRequest } from 'vs/workbench/contrib/chat/common/chatParserTypes';
1516
import { contentRefUrl } from '../common/annotations';
1617

@@ -20,7 +21,8 @@ export class ChatMarkdownDecorationsRenderer {
2021
constructor(
2122
@IKeybindingService private readonly keybindingService: IKeybindingService,
2223
@ILabelService private readonly labelService: ILabelService,
23-
@ILogService private readonly logService: ILogService
24+
@ILogService private readonly logService: ILogService,
25+
@IChatAgentService private readonly chatAgentService: IChatAgentService,
2426
) { }
2527

2628
convertParsedRequestToMarkdown(parsedRequest: IParsedChatRequest): string {
@@ -35,7 +37,15 @@ export class ChatMarkdownDecorationsRenderer {
3537
part instanceof ChatRequestAgentPart ? part.agent.id :
3638
'';
3739

38-
result += `[${part.text}](${variableRefUrl}?${title})`;
40+
let text = part.text;
41+
if (part instanceof ChatRequestAgentPart) {
42+
const isDupe = this.chatAgentService.getAgentsByName(part.agent.name).length > 1;
43+
if (isDupe) {
44+
text += ` (${part.agent.extensionPublisher})`;
45+
}
46+
}
47+
48+
result += `[${text}](${variableRefUrl}?${title})`;
3949
}
4050
}
4151

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ export class ChatExtensionPointHandler implements IWorkbenchContribution {
202202
providerDescriptor.id,
203203
{
204204
extensionId: extension.description.identifier,
205+
extensionPublisher: extension.description.publisherDisplayName ?? extension.description.publisher, // May not be present in OSS
205206
id: providerDescriptor.id,
206207
description: providerDescriptor.description,
207208
metadata: {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ class InputEditorDecorations extends Disposable {
213213
const textDecorations: IDecorationOptions[] | undefined = [];
214214
if (agentPart) {
215215
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}`;
216+
const publisher = isDupe ? `(${agentPart.agent.extensionPublisher}) ` : '';
217+
const agentHover = `${publisher}${agentPart.agent.description}`;
218218
textDecorations.push({ range: agentPart.editorRange, hoverMessage: new MarkdownString(agentHover) });
219219
if (agentSubcommandPart) {
220220
textDecorations.push({ range: agentSubcommandPart.editorRange, hoverMessage: new MarkdownString(agentSubcommandPart.command.description) });
@@ -361,7 +361,7 @@ class AgentCompletions extends Disposable {
361361
return <CompletionItem>{
362362
// Leading space is important because detail has no space at the start by design
363363
label: isDupe ?
364-
{ label: withAt, description: a.description, detail: ` (${a.id})` } :
364+
{ label: withAt, description: a.description, detail: ` (${a.extensionPublisher})` } :
365365
withAt,
366366
insertText: `${withAt} `,
367367
detail: a.description,
@@ -452,7 +452,7 @@ class AgentCompletions extends Disposable {
452452

453453
return {
454454
label: isDupe ?
455-
{ label: agentLabel, description: agent.description, detail: ` (${agent.id})` } :
455+
{ label: agentLabel, description: agent.description, detail: ` (${agent.extensionPublisher})` } :
456456
agentLabel,
457457
detail,
458458
filterText: `${chatSubcommandLeader}${agent.name}`,

src/vs/workbench/contrib/chat/common/chatAgents.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface IChatAgentData {
5151
name: string;
5252
description?: string;
5353
extensionId: ExtensionIdentifier;
54+
extensionPublisher: string;
5455
/** The agent invoked when no agent is specified */
5556
isDefault?: boolean;
5657
metadata: IChatAgentMetadata;
@@ -315,6 +316,7 @@ export class MergedChatAgent implements IChatAgent {
315316
get name(): string { return this.data.name ?? ''; }
316317
get description(): string { return this.data.description ?? ''; }
317318
get extensionId(): ExtensionIdentifier { return this.data.extensionId; }
319+
get extensionPublisher(): string { return this.data.extensionPublisher; }
318320
get isDefault(): boolean | undefined { return this.data.isDefault; }
319321
get metadata(): IChatAgentMetadata { return this.data.metadata; }
320322
get slashCommands(): IChatAgentCommand[] { return this.data.slashCommands; }

src/vs/workbench/contrib/chat/common/chatModel.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,17 @@ export class ChatModel extends Disposable implements IChatModel {
831831
vote: r.response?.vote,
832832
agent: r.response?.agent ?
833833
// May actually be the full IChatAgent instance, just take the data props. slashCommands don't matter here.
834-
{ id: r.response.agent.id, name: r.response.agent.name, description: r.response.agent.description, extensionId: r.response.agent.extensionId, metadata: r.response.agent.metadata, slashCommands: [], locations: r.response.agent.locations, isDefault: r.response.agent.isDefault }
834+
{
835+
id: r.response.agent.id,
836+
name: r.response.agent.name,
837+
description: r.response.agent.description,
838+
extensionId: r.response.agent.extensionId,
839+
metadata: r.response.agent.metadata,
840+
slashCommands: [],
841+
locations: r.response.agent.locations,
842+
isDefault: r.response.agent.isDefault,
843+
extensionPublisher: r.response.agent.extensionPublisher
844+
}
835845
: undefined,
836846
slashCommand: r.response?.slashCommand,
837847
usedContext: r.response?.usedContext,

src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_and_subcommand_after_newline.0.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
value: "nullExtensionDescription",
3333
_lower: "nullextensiondescription"
3434
},
35+
extensionPublisher: "",
3536
locations: [ "panel" ],
36-
metadata: { description: "" },
37+
metadata: { },
3738
slashCommands: [
3839
{
3940
name: "subCommand",

src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_and_subcommand_with_leading_whitespace.0.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
value: "nullExtensionDescription",
3333
_lower: "nullextensiondescription"
3434
},
35+
extensionPublisher: "",
3536
locations: [ "panel" ],
36-
metadata: { description: "" },
37+
metadata: { },
3738
slashCommands: [
3839
{
3940
name: "subCommand",

src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_with_question_mark.0.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
value: "nullExtensionDescription",
1919
_lower: "nullextensiondescription"
2020
},
21+
extensionPublisher: "",
2122
locations: [ "panel" ],
22-
metadata: { description: "" },
23+
metadata: { },
2324
slashCommands: [
2425
{
2526
name: "subCommand",

src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_with_subcommand_after_text.0.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
value: "nullExtensionDescription",
1919
_lower: "nullextensiondescription"
2020
},
21+
extensionPublisher: "",
2122
locations: [ "panel" ],
22-
metadata: { description: "" },
23+
metadata: { },
2324
slashCommands: [
2425
{
2526
name: "subCommand",

0 commit comments

Comments
 (0)