Path: blob/main/extensions/copilot/src/extension/prompts/node/panel/codeBlockFormattingRules.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 { BasePromptElementProps, PromptElement, PromptSizing } from '@vscode/prompt-tsx';6import { filepathCodeBlockMarker } from '../../../../util/common/markdown';7import { ExampleCodeBlock } from './safeElements';89export interface CodeBlockFormattingRulesPromptProps extends BasePromptElementProps {10readonly disableCodeBlockUris?: boolean;11}1213export const EXISTING_CODE_MARKER = '...existing code...';1415export class CodeBlockFormattingRules extends PromptElement<CodeBlockFormattingRulesPromptProps> {1617public override render(state: void, sizing: PromptSizing) {18return (19<>20When suggesting code changes or new content, use Markdown code blocks.<br />21To start a code block, use 4 backticks.<br />22After the backticks, add the programming language name.<br />23{24!this.props.disableCodeBlockUris &&25<>26If the code modifies an existing file or should be placed at a specific location, add a line comment with '{filepathCodeBlockMarker}' and the file path.<br />27If you want the user to decide where to place the code, do not add the file path comment.<br />28</>29}30In the code block, use a line comment with '{EXISTING_CODE_MARKER}' to indicate code that is already present in the file.<br />31<ExampleCodeBlock languageId='languageId' examplePath={'/path/to/file'} includeFilepath={true} minNumberOfBackticks={4}32code={33[34`// ${EXISTING_CODE_MARKER}`,35`{ changed code }`,36`// ${EXISTING_CODE_MARKER}`,37`{ changed code }`,38`// ${EXISTING_CODE_MARKER}`39].join('\n')40}41/>42</>43);44}45}4647