Skip to content

Commit 4c03026

Browse files
authored
Change code citation message, add telemetry (microsoft#223159)
1 parent 2238edf commit 4c03026

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,32 @@ import { Disposable } from 'vs/base/common/lifecycle';
99
import { Schemas } from 'vs/base/common/network';
1010
import { URI } from 'vs/base/common/uri';
1111
import { localize } from 'vs/nls';
12+
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1213
import { ChatTreeItem } from 'vs/workbench/contrib/chat/browser/chat';
1314
import { IChatContentPart, IChatContentPartRenderContext } from 'vs/workbench/contrib/chat/browser/chatContentParts/chatContentParts';
1415
import { IChatCodeCitations, IChatRendererContent } from 'vs/workbench/contrib/chat/common/chatViewModel';
1516
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
1617

18+
type ChatCodeCitationOpenedClassification = {
19+
owner: 'roblourens';
20+
comment: 'Indicates when a user opens chat code citations';
21+
};
22+
1723
export class ChatCodeCitationContentPart extends Disposable implements IChatContentPart {
1824
public readonly domNode: HTMLElement;
1925

2026
constructor(
2127
citations: IChatCodeCitations,
2228
context: IChatContentPartRenderContext,
23-
@IEditorService private readonly editorService: IEditorService
29+
@IEditorService private readonly editorService: IEditorService,
30+
@ITelemetryService private readonly telemetryService: ITelemetryService
2431
) {
2532
super();
2633

27-
const label = citations.citations.length > 1 ?
28-
localize('codeCitationsPlural', "This code matches {0} references in public repositories", citations.citations.length) :
29-
localize('codeCitation', "This code matches 1 reference in a public repository", citations.citations.length);
34+
const licenseTypes = citations.citations.reduce((set, c) => set.add(c.license), new Set<string>());
35+
const label = licenseTypes.size === 1 ?
36+
localize('codeCitation', "Similar code found with 1 license type", licenseTypes.size) :
37+
localize('codeCitations', "Similar code found with {0} license types", licenseTypes.size);
3038
const elements = dom.h('.chat-code-citation-message@root', [
3139
dom.h('span.chat-code-citation-label@label'),
3240
dom.h('.chat-code-citation-button-container@button'),
@@ -42,10 +50,11 @@ export class ChatCodeCitationContentPart extends Disposable implements IChatCont
4250
buttonSecondaryHoverBackground: undefined,
4351
buttonSeparator: undefined
4452
}));
45-
button.label = localize('viewReferences', "View references");
53+
button.label = localize('viewMatches', "View matches");
4654
this._register(button.onDidClick(() => {
4755
const citationText = citations.citations.map(c => `# [${c.license}]\n${c.value.toString()}\n\n\`\`\`\n${c.snippet}\n\`\`\`\n\n`).join('\n');
48-
this.editorService.openEditor({ resource: URI.from({ scheme: Schemas.untitled, path: 'Code references' }), contents: citationText, languageId: 'markdown' });
56+
this.editorService.openEditor({ resource: URI.from({ scheme: Schemas.untitled, path: 'Code Matches' }), contents: citationText, languageId: 'markdown' });
57+
this.telemetryService.publicLog2<{}, ChatCodeCitationOpenedClassification>('openedChatCodeCitations');
4958
}));
5059
this.domNode = elements.root;
5160
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { localize } from 'vs/nls';
76
import { asArray, firstOrDefault } from 'vs/base/common/arrays';
87
import { DeferredPromise } from 'vs/base/common/async';
98
import { Emitter, Event } from 'vs/base/common/event';
@@ -17,11 +16,12 @@ import { URI, UriComponents, UriDto, isUriComponents } from 'vs/base/common/uri'
1716
import { generateUuid } from 'vs/base/common/uuid';
1817
import { IOffsetRange, OffsetRange } from 'vs/editor/common/core/offsetRange';
1918
import { TextEdit } from 'vs/editor/common/languages';
19+
import { localize } from 'vs/nls';
2020
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2121
import { ILogService } from 'vs/platform/log/common/log';
2222
import { ChatAgentLocation, IChatAgentCommand, IChatAgentData, IChatAgentHistoryEntry, IChatAgentRequest, IChatAgentResult, IChatAgentService, reviveSerializedAgent } from 'vs/workbench/contrib/chat/common/chatAgents';
2323
import { ChatRequestTextPart, IParsedChatRequest, getPromptText, reviveParsedChatRequest } from 'vs/workbench/contrib/chat/common/chatParserTypes';
24-
import { IChatAgentMarkdownContentWithVulnerability, IChatCommandButton, IChatConfirmation, IChatContentInlineReference, IChatContentReference, IChatFollowup, IChatMarkdownContent, IChatProgressMessage, IChatResponseProgressFileTreeData, IChatTask, IChatTextEdit, IChatTreeData, IChatUsedContext, IChatWarningMessage, ChatAgentVoteDirection, isIUsedContext, IChatProgress, IChatCodeCitation } from 'vs/workbench/contrib/chat/common/chatService';
24+
import { ChatAgentVoteDirection, IChatAgentMarkdownContentWithVulnerability, IChatCodeCitation, IChatCommandButton, IChatConfirmation, IChatContentInlineReference, IChatContentReference, IChatFollowup, IChatMarkdownContent, IChatProgress, IChatProgressMessage, IChatResponseProgressFileTreeData, IChatTask, IChatTextEdit, IChatTreeData, IChatUsedContext, IChatWarningMessage, isIUsedContext } from 'vs/workbench/contrib/chat/common/chatService';
2525
import { IChatRequestVariableValue } from 'vs/workbench/contrib/chat/common/chatVariables';
2626

2727
export interface IChatRequestVariableEntry {

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type ChatProviderInvokedEvent = {
5252
agent: string;
5353
slashCommand: string | undefined;
5454
location: ChatAgentLocation;
55+
citations: number;
5556
};
5657

5758
type ChatProviderInvokedClassification = {
@@ -62,7 +63,8 @@ type ChatProviderInvokedClassification = {
6263
chatSessionId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'A random ID for the session.' };
6364
agent: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The type of agent used.' };
6465
slashCommand?: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The type of slashCommand used.' };
65-
location?: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The location at which chat request was made.' };
66+
location: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The location at which chat request was made.' };
67+
citations: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The number of public code citations that were returned with the response.' };
6668
owner: 'roblourens';
6769
comment: 'Provides insight into the performance of Chat agents.';
6870
};
@@ -461,6 +463,7 @@ export class ChatService extends Disposable implements IChatService {
461463
slashCommand: agentSlashCommandPart ? agentSlashCommandPart.command.name : commandPart?.slashCommand.command,
462464
chatSessionId: model.sessionId,
463465
location,
466+
citations: request?.response?.codeCitations.length ?? 0
464467
});
465468

466469
model.cancelRequest(request);
@@ -546,7 +549,8 @@ export class ChatService extends Disposable implements IChatService {
546549
agent: agentPart?.agent.id ?? '',
547550
slashCommand: agentSlashCommandPart ? agentSlashCommandPart.command.name : commandPart?.slashCommand.command,
548551
chatSessionId: model.sessionId,
549-
location
552+
location,
553+
citations: request.response?.codeCitations.length ?? 0
550554
});
551555
model.setResponse(request, rawResult);
552556
completeResponseCreated();
@@ -569,7 +573,8 @@ export class ChatService extends Disposable implements IChatService {
569573
agent: agentPart?.agent.id ?? '',
570574
slashCommand: agentSlashCommandPart ? agentSlashCommandPart.command.name : commandPart?.slashCommand.command,
571575
chatSessionId: model.sessionId,
572-
location
576+
location,
577+
citations: 0
573578
});
574579
this.logService.error(`Error while handling chat request: ${toErrorMessage(err, true)}`);
575580
if (request) {

0 commit comments

Comments
 (0)