add modify_actions command to test diff
This commit is contained in:
parent
25915cec29
commit
a3ee988167
@ -29,7 +29,7 @@ export interface Command {
|
||||
this.commands.push(command);
|
||||
}
|
||||
|
||||
getCommandList(): Command[] {
|
||||
getCommandList(includeHide: boolean = false): Command[] {
|
||||
// load commands from CustomCommands
|
||||
let newCommands: Command[] = [...this.commands];
|
||||
const customCommands = CustomCommands.getInstance();
|
||||
@ -43,7 +43,9 @@ export interface Command {
|
||||
return CustomCommands.getInstance().handleCommand(commandName);
|
||||
}
|
||||
};
|
||||
newCommands.push(commandObj);
|
||||
if (command.show || includeHide) {
|
||||
newCommands.push(commandObj);
|
||||
}
|
||||
});
|
||||
return newCommands;
|
||||
}
|
||||
@ -75,7 +77,7 @@ export interface Command {
|
||||
|
||||
// 处理所有命令
|
||||
let result = text;
|
||||
for (const commandObj of this.getCommandList()) {
|
||||
for (const commandObj of this.getCommandList(true)) {
|
||||
result = await processCommand(commandObj, result);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ interface Command {
|
||||
description: string;
|
||||
message: string;
|
||||
default: boolean;
|
||||
show: boolean;
|
||||
instructions: string[];
|
||||
}
|
||||
|
||||
@ -43,6 +44,7 @@ class CustomCommands {
|
||||
description: settings.description,
|
||||
message: settings.message,
|
||||
default: settings.default,
|
||||
show: settings.show === undefined ? "true": settings.show,
|
||||
instructions: settings.instructions
|
||||
};
|
||||
this.commands.push(command);
|
||||
|
8
workflows/code_actions/_setting_.json
Normal file
8
workflows/code_actions/_setting_.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"pattern": "modify_actions",
|
||||
"description": "generate modify action list",
|
||||
"message": "output modify action list.",
|
||||
"default": false,
|
||||
"show": false,
|
||||
"instructions": ["instruct.txt"]
|
||||
}
|
78
workflows/code_actions/instruct.txt
Normal file
78
workflows/code_actions/instruct.txt
Normal file
@ -0,0 +1,78 @@
|
||||
As a software developer assistant, your tasks are to:
|
||||
|
||||
- Provide a clear and concise response to address the user's requirements.
|
||||
- Write code and give advice based on given code or information in the <context> if provided.
|
||||
- Follow language-specific best practices and common coding standards.
|
||||
|
||||
When responding:
|
||||
|
||||
1. 输出为修改动作列表。例如:
|
||||
```
|
||||
```json
|
||||
[
|
||||
{
|
||||
"action": "delete",
|
||||
"content": "} catch (error) {\n\t}"
|
||||
},
|
||||
{
|
||||
"action": "insert",
|
||||
"insert_before": "try {\n\tconst v = 30;",
|
||||
"content": "const val = 50;"
|
||||
},
|
||||
{
|
||||
"action": "insert",
|
||||
"insert_after": "try {\n\tconst v = 0;",
|
||||
"content": "const val = 20;"
|
||||
},
|
||||
{
|
||||
"action": "modify",
|
||||
"original_content": "const newVal = 30;",
|
||||
"new_content": "const newVal = 35;"
|
||||
}
|
||||
]
|
||||
```
|
||||
```
|
||||
2. insert_before、insert_after尽量对应多行内容,避免原代码中存在多个匹配位置。例如:
|
||||
原代码为:
|
||||
```
|
||||
def hello1():
|
||||
print('a')
|
||||
def hello2():
|
||||
print('a')
|
||||
```
|
||||
针对insert_after来说,好的修改是:
|
||||
```
|
||||
'insert_after': 'def hello2():\n print('a')'
|
||||
```
|
||||
不好的修改示例:
|
||||
```
|
||||
'insert_after': ' print('a')'
|
||||
```
|
||||
不好的示例中会有多个匹配成功的位置,会产生插入内容位置错误。
|
||||
3. 需要插入到语句块之后的内容,不能插入到语句块中间。例如:
|
||||
```
|
||||
def hello():
|
||||
a = 30;
|
||||
if a>30:
|
||||
print('a')
|
||||
else:
|
||||
print('b')
|
||||
```
|
||||
如果需要在if语句块之后插入新内容,那么正确的写法是:
|
||||
```
|
||||
{
|
||||
"action": "insert",
|
||||
"insert_after": "\tif a>30:\n\t\tprint('a')"\n\telse:\n\t\tprint('b')",
|
||||
"content": "print('c')"
|
||||
}
|
||||
```
|
||||
错误的写法是:
|
||||
```
|
||||
{
|
||||
"action": "insert",
|
||||
"insert_after": "\tif a>30:",
|
||||
"content": "print('c')"
|
||||
}
|
||||
```
|
||||
4. 新插入代码,如果有多个位置适合插入,那么插入到第一个合适位置。
|
||||
5. 插入函数时,确保插入到对应语句完整代码块之后或之前,避免对原代码块有语法结构的破坏。
|
Loading…
x
Reference in New Issue
Block a user