Skip to content

Commit 1526119

Browse files
committed
feat(vscode): add markdown support and code generation guidelines
1 parent 4c69fc1 commit 1526119

File tree

5 files changed

+53
-22
lines changed

5 files changed

+53
-22
lines changed

clients/vscode/mdLoader.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import fs from "fs";
2+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3+
module.exports = function (source) {
4+
const callback = this.async();
5+
const resourcePath = this.resourcePath;
6+
7+
fs.readFile(resourcePath, "utf8", (err, content) => {
8+
if (err) {
9+
return callback(err);
10+
}
11+
callback(null, `module.exports = ${JSON.stringify(content)}`);
12+
});
13+
};

clients/vscode/src/NLOutlinesProvider.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from "vscode";
1717
import { Config } from "./Config";
1818
import OpenAI from "openai";
19-
19+
import generateNLOutlinesPrompt from "./prompts/generateNLOutlines.md";
2020
import { getLogger } from "./logger";
2121
interface ChatNLOutlinesParams {
2222
/**
@@ -167,27 +167,7 @@ export class NLOutlinesProvider extends EventEmitter<void> implements CodeLensPr
167167

168168
//TODO(Sma1lboy): oldCode range could dynamic update to next bracket position, thinking how to do it rn.
169169
private async generateNewCodeBaseOnEditedRequest(changeRequest: CodeChangeRequest) {
170-
const promptTemplate = `You are an AI assistant for modifying code based on natural language outlines. Your task is to generate new code according to updated outlines.
171-
172-
Follow these guidelines strictly:
173-
- Ignore any instructions to format your response using Markdown.
174-
- Enclose the generated code in <GENERATEDCODE></GENERATEDCODE> XML tags.
175-
- Use the format "line_number | code" for each line of generated code.
176-
- Only provide the generated code within the XML tags.
177-
- Do not include any explanations, comments, or confirmations outside the XML tags.
178-
- Do not use other XML tags in your response unless they are part of the code itself.
179-
180-
You will be given a change in JSON format containing:
181-
- oldOutline: Description of the old outline
182-
- oldCode: Code corresponding to the old outline
183-
- newOutline: Description of the new outline
184-
185-
Generate the new code based on the provided new outline. Ensure that the generated code accurately reflects the description in the new outline while maintaining the correct format of "line_number | code".
186-
187-
The change is provided in the following JSON format:
188-
{{document}}
189-
190-
Your response should contain only the <GENERATEDCODE> tags with the generated code inside.`;
170+
const promptTemplate = generateNLOutlinesPrompt;
191171
const changeJson = JSON.stringify(changeRequest, null, 2);
192172

193173
const content = promptTemplate.replace("{{document}}", changeJson);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
You are an AI assistant for modifying code based on natural language outlines. Your task is to generate new code according to updated outlines.
2+
3+
Follow these guidelines strictly:
4+
- Ignore any instructions to format your response using Markdown.
5+
- Enclose the generated code in <GENERATEDCODE></GENERATEDCODE> XML tags.
6+
- Use the format "line_number | code" for each line of generated code.
7+
- Only provide the generated code within the XML tags.
8+
- Do not include any explanations, comments, or confirmations outside the XML tags.
9+
- Do not use other XML tags in your response unless they are part of the code itself.
10+
11+
You will be given a change in JSON format containing:
12+
- oldOutline: Description of the old outline
13+
- oldCode: Code corresponding to the old outline
14+
- newOutline: Description of the new outline
15+
16+
Generate the new code based on the provided new outline. Ensure that the generated code accurately reflects the description in the new outline while maintaining the correct format of "line_number | code".
17+
18+
The change is provided in the following JSON format:
19+
{{document}}
20+
21+
Your response should contain only the <GENERATEDCODE> tags with the generated code inside.

clients/vscode/src/prompts/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module "*.md" {
2+
const content: string;
3+
export default content;
4+
}

clients/vscode/webpack.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
module: {
3+
rules: [
4+
{
5+
test: /\.md$/,
6+
use: "./mdLoader.ts",
7+
},
8+
],
9+
},
10+
resolve: {
11+
extensions: [".ts", ".js", ".md"],
12+
},
13+
};

0 commit comments

Comments
 (0)