Path: blob/main/src/vs/workbench/contrib/chat/browser/chatContentParts/chatCodeCitationContentPart.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as dom from '../../../../../base/browser/dom.js';6import { Button } from '../../../../../base/browser/ui/button/button.js';7import { Disposable } from '../../../../../base/common/lifecycle.js';8import { localize } from '../../../../../nls.js';9import { ITelemetryService } from '../../../../../platform/telemetry/common/telemetry.js';10import { ChatTreeItem } from '../chat.js';11import { IChatContentPart, IChatContentPartRenderContext } from './chatContentParts.js';12import { getCodeCitationsMessage } from '../../common/chatModel.js';13import { IChatCodeCitations, IChatRendererContent } from '../../common/chatViewModel.js';14import { IEditorService } from '../../../../services/editor/common/editorService.js';1516type ChatCodeCitationOpenedClassification = {17owner: 'roblourens';18comment: 'Indicates when a user opens chat code citations';19};2021export class ChatCodeCitationContentPart extends Disposable implements IChatContentPart {22public readonly domNode: HTMLElement;2324constructor(25citations: IChatCodeCitations,26context: IChatContentPartRenderContext,27@IEditorService private readonly editorService: IEditorService,28@ITelemetryService private readonly telemetryService: ITelemetryService29) {30super();3132const label = getCodeCitationsMessage(citations.citations);33const elements = dom.h('.chat-code-citation-message@root', [34dom.h('span.chat-code-citation-label@label'),35dom.h('.chat-code-citation-button-container@button'),36]);37elements.label.textContent = label + ' - ';38const button = this._register(new Button(elements.button, {39buttonBackground: undefined,40buttonBorder: undefined,41buttonForeground: undefined,42buttonHoverBackground: undefined,43buttonSecondaryBackground: undefined,44buttonSecondaryForeground: undefined,45buttonSecondaryHoverBackground: undefined,46buttonSeparator: undefined47}));48button.label = localize('viewMatches', "View matches");49this._register(button.onDidClick(() => {50const 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');51this.editorService.openEditor({ resource: undefined, contents: citationText, languageId: 'markdown' });52this.telemetryService.publicLog2<{}, ChatCodeCitationOpenedClassification>('openedChatCodeCitations');53}));54this.domNode = elements.root;55}5657hasSameContent(other: IChatRendererContent, followingContent: IChatRendererContent[], element: ChatTreeItem): boolean {58return other.kind === 'codeCitations';59}60}616263