Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/chatContentParts/chatCodeCitationContentPart.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as dom from '../../../../../base/browser/dom.js';
7
import { Button } from '../../../../../base/browser/ui/button/button.js';
8
import { Disposable } from '../../../../../base/common/lifecycle.js';
9
import { localize } from '../../../../../nls.js';
10
import { ITelemetryService } from '../../../../../platform/telemetry/common/telemetry.js';
11
import { ChatTreeItem } from '../chat.js';
12
import { IChatContentPart, IChatContentPartRenderContext } from './chatContentParts.js';
13
import { getCodeCitationsMessage } from '../../common/chatModel.js';
14
import { IChatCodeCitations, IChatRendererContent } from '../../common/chatViewModel.js';
15
import { IEditorService } from '../../../../services/editor/common/editorService.js';
16
17
type ChatCodeCitationOpenedClassification = {
18
owner: 'roblourens';
19
comment: 'Indicates when a user opens chat code citations';
20
};
21
22
export class ChatCodeCitationContentPart extends Disposable implements IChatContentPart {
23
public readonly domNode: HTMLElement;
24
25
constructor(
26
citations: IChatCodeCitations,
27
context: IChatContentPartRenderContext,
28
@IEditorService private readonly editorService: IEditorService,
29
@ITelemetryService private readonly telemetryService: ITelemetryService
30
) {
31
super();
32
33
const label = getCodeCitationsMessage(citations.citations);
34
const elements = dom.h('.chat-code-citation-message@root', [
35
dom.h('span.chat-code-citation-label@label'),
36
dom.h('.chat-code-citation-button-container@button'),
37
]);
38
elements.label.textContent = label + ' - ';
39
const button = this._register(new Button(elements.button, {
40
buttonBackground: undefined,
41
buttonBorder: undefined,
42
buttonForeground: undefined,
43
buttonHoverBackground: undefined,
44
buttonSecondaryBackground: undefined,
45
buttonSecondaryForeground: undefined,
46
buttonSecondaryHoverBackground: undefined,
47
buttonSeparator: undefined
48
}));
49
button.label = localize('viewMatches', "View matches");
50
this._register(button.onDidClick(() => {
51
const citationText = `# Code Citations\n\n` + citations.citations.map(c => `## License: ${c.license}\n${c.value.toString()}\n\n\`\`\`\n${c.snippet}\n\`\`\`\n\n`).join('\n');
52
this.editorService.openEditor({ resource: undefined, contents: citationText, languageId: 'markdown' });
53
this.telemetryService.publicLog2<{}, ChatCodeCitationOpenedClassification>('openedChatCodeCitations');
54
}));
55
this.domNode = elements.root;
56
}
57
58
hasSameContent(other: IChatRendererContent, followingContent: IChatRendererContent[], element: ChatTreeItem): boolean {
59
return other.kind === 'codeCitations';
60
}
61
}
62
63