Skip to content

Commit c83a7c4

Browse files
committed
fix:修正tcvb解析
1 parent fee0307 commit c83a7c4

File tree

3 files changed

+107
-95
lines changed

3 files changed

+107
-95
lines changed

prompt/savefile.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
tcvb���ؽ��յ�ʱ�������̣���׺tcvb��������merge֮���cvb�ļ�һ����
2-
analyze�Ľ��Ҳ���̣������md����������Ҳһ����
1+
doUploadCommand ���ص�respond ��� tcvb���ݡ�����ȷ��merge���Գɹ���˵��tcvb��ʽ��ȷ����Ҳ��һ�ݡ���׺tcvb���ļ�����merge֮���cvb�ļ�һ����ֻ�Ǻ�׺��ͬ��
2+
analyze�Ľ��Ҳ���̣������.md����������Ҳһ����
33
ע�⣬�¼ӵ��������̶�Ҫ����sidebar����ʾ

prompt/testdata2.txt

Lines changed: 104 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,119 @@
1-
```markdown
2-
## BEGIN_TCVB
3-
## FILE:k:\lab\CodeReDesign-dummy\src\extension.ts
1+
## BEGIN_TCVB
2+
## FILE:k:\lab\CodeReDesign-dummy\src\cvbManager.ts
43
## OPERATION:GLOBAL-REPLACE
54
## OLD_CONTENT
6-
```typescript
7-
let apiResponse = await queryCodeReDesign(cvbContent, userPrompt, outputChannel, getCurrentOperationController().signal);
8-
let processSuccess = true;
9-
do{
10-
try {
11-
if (apiResponse) {
12-
const tcvb = new TCVB(apiResponse);
13-
const oldCvb = new Cvb(cvbContent);
14-
const cvb = mergeCvb(oldCvb, tcvb);
15-
16-
processSuccess = true;
5+
```
6+
export async function doUploadCommand(cvbFilePath: string, userPrompt: string, outputChannel: vscode.OutputChannel){
7+
const workspaceFolders = vscode.workspace.workspaceFolders;
8+
if (!workspaceFolders) {
9+
vscode.window.showErrorMessage('No workspace folder found');
10+
return;
11+
}
12+
13+
const workspacePath = workspaceFolders[0].uri.fsPath;
14+
const tmpDir = path.join(workspacePath, '.CodeReDesignWorkSpace');
1715

18-
cvb.setMetaData("用户需求", userPrompt);
19-
const newCvbFilePath = path.join(tmpDir, fileName);
20-
fs.writeFileSync(newCvbFilePath, cvb.toString(), 'utf-8');
21-
vscode.window.showInformationMessage(`API response saved as CVB file: ${newCvbFilePath}`);
22-
}
23-
} catch (err : any){
24-
apiResponse = await callDeepSeekFixApi(err.message, outputChannel, true, getCurrentOperationController().signal);
25-
processSuccess = false;
16+
const filenameSummary = await generateFilenameFromRequest(userPrompt);
17+
const timestamp = generateTimestamp();
18+
let baseFileName = `${timestamp}_${filenameSummary}.cvb`;
19+
let fileName = baseFileName;
20+
let i = 1;
21+
while (fs.existsSync(path.join(tmpDir, fileName))) {
22+
fileName = `${timestamp}_${filenameSummary}_${i}.cvb`;
23+
i++;
2624
}
27-
} while (!processSuccess);
28-
```
29-
## NEW_CONTENT
30-
```typescript
31-
let apiResponse = await queryCodeReDesign(cvbContent, userPrompt, outputChannel, getCurrentOperationController().signal);
32-
let processSuccess = true;
33-
do{
34-
try {
35-
if (apiResponse) {
36-
const tcvb = new TCVB(apiResponse);
37-
const oldCvb = new Cvb(cvbContent);
38-
const tcvbFilePath = path.join(tmpDir, `${fileName}.tcvb`);
39-
fs.writeFileSync(tcvbFilePath, tcvb.toString(), 'utf-8');
4025

41-
const cvb = mergeCvb(oldCvb, tcvb);
26+
const cvbContent = fs.readFileSync(cvbFilePath, 'utf-8');
4227

43-
processSuccess = true;
28+
resetCurrentOperationController();
4429

45-
cvb.setMetaData("用户需求", userPrompt);
46-
const newCvbFilePath = path.join(tmpDir, fileName);
47-
fs.writeFileSync(newCvbFilePath, cvb.toString(), 'utf-8');
48-
vscode.window.showInformationMessage(`API response saved as CVB file: ${newCvbFilePath}`);
49-
}
50-
} catch (err : any){
51-
apiResponse = await callDeepSeekFixApi(err.message, outputChannel, true, getCurrentOperationController().signal);
52-
processSuccess = false;
53-
}
54-
} while (!processSuccess);
55-
```
56-
## OPERATION:GLOBAL-REPLACE
57-
## OLD_CONTENT
58-
```typescript
59-
const analysisResult = await analyzeCode(cvbContent, userRequest, outputChannel, getCurrentOperationController().signal);
60-
if (analysisResult) {
61-
vscode.window.showInformationMessage('Analysis completed. Check the output channel for details.');
62-
}
30+
let apiResponse = await queryCodeReDesign(cvbContent, userPrompt, outputChannel, getCurrentOperationController().signal);
31+
let processSuccess = true;
32+
do {
33+
try {
34+
if (apiResponse) {
35+
const tcvb = new TCVB(apiResponse);
36+
const oldCvb = new Cvb(cvbContent);
37+
const cvb = mergeCvb(oldCvb, tcvb);
6338

64-
vscode.window.showInformationMessage('解析完毕');
65-
```
66-
## NEW_CONTENT
67-
```typescript
68-
const analysisResult = await analyzeCode(cvbContent, userRequest, outputChannel, getCurrentOperationController().signal);
69-
if (analysisResult) {
70-
const analysisFilePath = path.join(tmpDir, `${fileName}.md`);
71-
fs.writeFileSync(analysisFilePath, analysisResult, 'utf-8');
72-
vscode.window.showInformationMessage(`Analysis result saved as file: ${analysisFilePath}`);
73-
}
39+
processSuccess = true;
7440

75-
vscode.window.showInformationMessage('解析完毕');
76-
```
41+
cvb.setMetaData("用户需求", userPrompt);
42+
const newCvbFilePath = path.join(tmpDir, fileName);
43+
fs.writeFileSync(newCvbFilePath, cvb.toString(), 'utf-8');
44+
vscode.window.showInformationMessage(`API response saved as CVB file: ${newCvbFilePath}`);
45+
}
46+
} catch (err : any){
47+
vscode.window.showInformationMessage(`API response have error ${err.message}, try fix ...`);
48+
apiResponse = await callDeepSeekFixApi(err.message, outputChannel, true, getCurrentOperationController().signal);
49+
processSuccess = false;
50+
}
51+
} while (!processSuccess);
7752

78-
## FILE:k:\lab\CodeReDesign-dummy\src\siderBar.ts
79-
## OPERATION:EXACT-REPLACE
80-
## OLD_CONTENT
81-
```typescript
82-
if (file.endsWith('.cvb')) {
83-
const filePath = path.join(targetFolder, file);
84-
cvbFiles.push(new CvbFile(file, vscode.Uri.file(filePath)));
53+
clearCurrentOperationController();
8554
}
8655
```
8756
## NEW_CONTENT
88-
```typescript
89-
if (file.endsWith('.cvb') || file.endsWith('.tcvb') || file.endsWith('.md')) {
90-
const filePath = path.join(targetFolder, file);
91-
cvbFiles.push(new CvbFile(file, vscode.Uri.file(filePath)));
92-
}
93-
```
94-
## BEFORE_ANCHOR
95-
```typescript
96-
const files = fs.readdirSync(targetFolder);
97-
files.forEach(file => {
9857
```
99-
## AFTER_ANCHOR
100-
```typescript
101-
// 新增排序逻辑
102-
cvbFiles.sort((a, b) =>
103-
a.label.localeCompare(b.label, undefined, { sensitivity: 'base' })
104-
);
58+
export async function doUploadCommand(cvbFilePath: string, userPrompt: string, outputChannel: vscode.OutputChannel){
59+
const workspaceFolders = vscode.workspace.workspaceFolders;
60+
if (!workspaceFolders) {
61+
vscode.window.showErrorMessage('No workspace folder found');
62+
return;
63+
}
64+
65+
const workspacePath = workspaceFolders[0].uri.fsPath;
66+
const tmpDir = path.join(workspacePath, '.CodeReDesignWorkSpace');
67+
68+
const filenameSummary = await generateFilenameFromRequest(userPrompt);
69+
const timestamp = generateTimestamp();
70+
let baseFileName = `${timestamp}_${filenameSummary}.cvb`;
71+
let fileName = baseFileName;
72+
let i = 1;
73+
while (fs.existsSync(path.join(tmpDir, fileName))) {
74+
fileName = `${timestamp}_${filenameSummary}_${i}.cvb`;
75+
i++;
76+
}
77+
78+
const cvbContent = fs.readFileSync(cvbFilePath, 'utf-8');
79+
80+
resetCurrentOperationController();
81+
82+
let apiResponse = await queryCodeReDesign(cvbContent, userPrompt, outputChannel, getCurrentOperationController().signal);
83+
let processSuccess = true;
84+
do {
85+
try {
86+
if (apiResponse) {
87+
const tcvb = new TCVB(apiResponse);
88+
const oldCvb = new Cvb(cvbContent);
89+
const cvb = mergeCvb(oldCvb, tcvb);
90+
91+
processSuccess = true;
92+
93+
cvb.setMetaData("用户需求", userPrompt);
94+
const newCvbFilePath = path.join(tmpDir, fileName);
95+
fs.writeFileSync(newCvbFilePath, cvb.toString(), 'utf-8');
96+
vscode.window.showInformationMessage(`API response saved as CVB file: ${newCvbFilePath}`);
97+
98+
// 保存 TCVB 文件
99+
const tcvbFilePath = path.join(tmpDir, fileName.replace(/\.cvb$/, '.tcvb'));
100+
fs.writeFileSync(tcvbFilePath, apiResponse, 'utf-8');
101+
102+
// 保存分析结果
103+
const analysisResult = await analyzeCode(cvbContent, userPrompt, outputChannel, getCurrentOperationController().signal);
104+
if (analysisResult) {
105+
const mdFilePath = path.join(tmpDir, fileName.replace(/\.cvb$/, '.md'));
106+
fs.writeFileSync(mdFilePath, analysisResult, 'utf-8');
107+
}
108+
}
109+
} catch (err : any){
110+
vscode.window.showInformationMessage(`API response have error ${err.message}, try fix ...`);
111+
apiResponse = await callDeepSeekFixApi(err.message, outputChannel, true, getCurrentOperationController().signal);
112+
processSuccess = false;
113+
}
114+
} while (!processSuccess);
115+
116+
clearCurrentOperationController();
117+
}
105118
```
106-
## END_TCVB
107-
```
119+
## END_TCVB

src/cvbManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export class TCVB
248248
tcStrContent = arrTCVBMatch[1];
249249

250250
// 匹配文件块,每个文件块以 "## FILE:" 开头
251-
const regFileBlock: RegExp = /^## FILE:(.*?)\n([\s\S]*?)(?=^## FILE:|^## END_TCVB)/gm;
251+
const regFileBlock: RegExp = /^## FILE:(.*?)\n([\s\S]*?)(?=^## FILE:|(?![\s\S]))/gm;
252252
let arrFileMatch: RegExpExecArray | null;
253253
while ((arrFileMatch = regFileBlock.exec(tcStrContent)) !== null)
254254
{

0 commit comments

Comments
 (0)