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