Path: blob/main/extensions/copilot/src/extension/prompts/node/panel/unsafeElements.tsx
13405 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 { PromptElement, PromptElementProps, TextChunk } from '@vscode/prompt-tsx';6import type * as vscode from 'vscode';7import { IPromptPathRepresentationService } from '../../../../platform/prompts/common/promptPathRepresentationService';8import { createFencedCodeBlock } from '../../../../util/common/markdown';910export type UnsafeCodeBlockProps = PromptElementProps<{11code: string;12languageId?: string;13/**14* Invokes `code.trim()`15*16* @default true17*/18shouldTrim?: boolean;19includeFilepath?: boolean;20uri?: vscode.Uri;21}>;2223/**24* !!! WARNING: Do not use this element for text from user's code files, instead use `SafeCodeBlock` from {@link file://./safeElements.tsx} !!!25*/26export class UnsafeCodeBlock extends PromptElement<UnsafeCodeBlockProps> {27constructor(props: UnsafeCodeBlockProps,28@IPromptPathRepresentationService private readonly _promptPathRepresentationService: IPromptPathRepresentationService,29) {30super(props);31}3233async render() {34const filePath = this.props.uri && this.props.includeFilepath ? this._promptPathRepresentationService.getFilePath(this.props.uri) : undefined;35const code = createFencedCodeBlock(this.props.languageId ?? '', this.props.code, this.props.shouldTrim ?? true, filePath);36return <TextChunk>37{code}38</TextChunk>;39}40}414243