|
1 | | -```TCVB |
| 1 | +```markdown |
2 | 2 | ## BEGIN_TCVB |
3 | | - |
4 | | -## FILE:k:\lab\CodeReDesign-dummy\src\siderBar.ts |
5 | | -## OPERATION:INSERT |
6 | | -## BEFORE_ANCHOR |
| 3 | +## FILE:k:\lab\CodeReDesign-dummy\src\extension.ts |
| 4 | +## OPERATION:GLOBAL-REPLACE |
| 5 | +## OLD_CONTENT |
7 | 6 | ```typescript |
8 | | -export function registerCvbContextMenu(context: vscode.ExtensionContext) { |
| 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); |
9 | 15 |
|
10 | | - // 注册右键菜单命令 |
11 | | - const applyCvbCommand = vscode.commands.registerCommand('codeReDesign.applyThisCvb', (cvb: CvbFile) => { |
12 | | -``` |
13 | | -## AFTER_ANCHOR |
14 | | -```typescript |
15 | | - const workspaceFolders = vscode.workspace.workspaceFolders; |
16 | | - if (workspaceFolders) { |
17 | | - const targetFolder = path.join(workspaceFolders[0].uri.fsPath, '.CodeReDesignWorkSpace'); // 替换为你的子文件夹名称 |
| 16 | + processSuccess = true; |
18 | 17 |
|
19 | | - // 创建文件系统监听器 |
| 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; |
| 26 | + } |
| 27 | +} while (!processSuccess); |
20 | 28 | ``` |
21 | | -## INSERT_CONTENT |
| 29 | +## NEW_CONTENT |
22 | 30 | ```typescript |
23 | | - // 监听 .tcvb 和 .md 文件变化 |
24 | | - const markdownWatcher = vscode.workspace.createFileSystemWatcher( |
25 | | - new vscode.RelativePattern(targetFolder, '**/*.md') |
26 | | - ); |
| 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'); |
27 | 40 |
|
28 | | - const tcvbWatcher = vscode.workspace.createFileSystemWatcher( |
29 | | - new vscode.RelativePattern(targetFolder, '**/*.tcvb') |
30 | | - ); |
| 41 | + const cvb = mergeCvb(oldCvb, tcvb); |
31 | 42 |
|
32 | | - // 当文件变化时刷新视图 |
33 | | - markdownWatcher.onDidCreate(() => cvbViewProvider.refresh()); |
34 | | - markdownWatcher.onDidDelete(() => cvbViewProvider.refresh()); |
35 | | - markdownWatcher.onDidChange(() => cvvViewProvider.refresh()); |
| 43 | + processSuccess = true; |
36 | 44 |
|
37 | | - tcvbWatcher.onDidCreate(() => cvbViewProvider.refresh()); |
38 | | - tcvbWatcher.onDidDelete(() => cvbViewProvider.refresh()); |
39 | | - tcvbWatcher.onDidChange(() => cvbViewProvider.refresh()); |
| 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 | +} |
40 | 63 |
|
41 | | - // 将监听器添加到订阅中,确保扩展销毁时清理资源 |
42 | | - context.subscriptions.push(markdownWatcher, tcvbWatcher); |
43 | | - } |
| 64 | +vscode.window.showInformationMessage('解析完毕'); |
44 | 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 | +} |
45 | 74 |
|
46 | | -## FILE:k:\lab\CodeReDesign-dummy\src\deepseekApi.ts |
47 | | -## OPERATION:INSERT |
48 | | -## BEFORE_ANCHOR |
| 75 | +vscode.window.showInformationMessage('解析完毕'); |
| 76 | +``` |
| 77 | + |
| 78 | +## FILE:k:\lab\CodeReDesign-dummy\src\siderBar.ts |
| 79 | +## OPERATION:EXACT-REPLACE |
| 80 | +## OLD_CONTENT |
49 | 81 | ```typescript |
50 | | - if (apiResponse) { |
51 | | - apiResponse = apiResponse.replace(/\r\n?/g, "\n"); |
52 | | - const tcvb = new TCVB(apiResponse); |
| 82 | +if (file.endsWith('.cvb')) { |
| 83 | + const filePath = path.join(targetFolder, file); |
| 84 | + cvbFiles.push(new CvbFile(file, vscode.Uri.file(filePath))); |
| 85 | +} |
53 | 86 | ``` |
54 | | -## AFTER_ANCHOR |
| 87 | +## 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 |
55 | 95 | ```typescript |
56 | | - cvb.setMetaData("用户需求", userPrompt); |
57 | | - const newCvbFilePath = path.join(tmpDir, fileName); |
58 | | - fs.writeFileSync(newCvbFilePath, cvb.toString(), 'utf-8'); |
| 96 | +const files = fs.readdirSync(targetFolder); |
| 97 | +files.forEach(file => { |
59 | 98 | ``` |
60 | | -## INSERT_CONTENT |
| 99 | +## AFTER_ANCHOR |
61 | 100 | ```typescript |
62 | | - // 保存 TCVB 文件 |
63 | | - const tcvbFilename = path.join(tmpDir, `${path.basename(fileName, '.cvb')}.tcvb`); |
64 | | - fs.writeFileSync(tcvbFilename, apiResponse, 'utf-8'); |
65 | | - |
66 | | - // 保存分析结果 |
67 | | - const analysisFilename = path.join(tmpDir, `${path.basename(fileName, '.cvb')}_analysis.md`); |
68 | | - fs.writeFileSync(analysisFilename, '分析结果\n\n' + analysisResult, 'utf-8'); |
| 101 | +// 新增排序逻辑 |
| 102 | +cvbFiles.sort((a, b) => |
| 103 | + a.label.localeCompare(b.label, undefined, { sensitivity: 'base' }) |
| 104 | +); |
69 | 105 | ``` |
70 | | - |
71 | 106 | ## END_TCVB |
72 | 107 | ``` |
0 commit comments