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