|
1 | | -## BEGIN_TCVB |
| 1 | +```TCVB |
| 2 | +## BEGIN_TCVB |
| 3 | + |
2 | 4 | ## FILE:k:\lab\CodeReDesign-dummy\src\siderBar.ts |
3 | 5 | ## OPERATION:INSERT |
4 | 6 | ## BEFORE_ANCHOR |
5 | 7 | ```typescript |
6 | | - getTreeItem(element: CvbFile): vscode.TreeItem { |
7 | | - return element; |
8 | | - } |
9 | | -``` |
10 | | -## AFTER_ANCHOR |
11 | | -```typescript |
12 | | - async getChildren(element?: CvbFile): Promise<CvbFile[]> { |
13 | | - if (element) { |
14 | | -``` |
15 | | -## INSERT_CONTENT |
16 | | -```typescript |
17 | | - // 新增文件类型过滤 |
18 | | - private isSupportedFileType(filename: string): boolean { |
19 | | - return filename.endsWith('.cvb') || filename.endsWith('.tcvb') || filename.endsWith('.md'); |
20 | | - } |
21 | | -``` |
| 8 | +export function registerCvbContextMenu(context: vscode.ExtensionContext) { |
22 | 9 |
|
23 | | -## OPERATION:SINGLE-REPLACE |
24 | | -## BEFORE_ANCHOR |
25 | | -```typescript |
26 | | - if (file.endsWith('.cvb')) { |
27 | | - const filePath = path.join(targetFolder, file); |
28 | | - cvbFiles.push(new CvbFile(file, vscode.Uri.file(filePath))); |
29 | | - } |
| 10 | + // 注册右键菜单命令 |
| 11 | + const applyCvbCommand = vscode.commands.registerCommand('codeReDesign.applyThisCvb', (cvb: CvbFile) => { |
30 | 12 | ``` |
31 | 13 | ## AFTER_ANCHOR |
32 | 14 | ```typescript |
33 | | - // 新增排序逻辑 |
34 | | - cvbFiles.sort((a, b) => |
35 | | -``` |
36 | | -## OLD_CONTENT |
37 | | -```typescript |
38 | | - if (file.endsWith('.cvb')) { |
39 | | - const filePath = path.join(targetFolder, file); |
40 | | - cvbFiles.push(new CvbFile(file, vscode.Uri.file(filePath))); |
41 | | - } |
42 | | -``` |
43 | | -## NEW_CONTENT |
44 | | -```typescript |
45 | | - if (this.isSupportedFileType(file)) { |
46 | | - const filePath = path.join(targetFolder, file); |
47 | | - cvbFiles.push(new CvbFile(file, vscode.Uri.file(filePath))); |
48 | | - } |
49 | | -``` |
| 15 | + const workspaceFolders = vscode.workspace.workspaceFolders; |
| 16 | + if (workspaceFolders) { |
| 17 | + const targetFolder = path.join(workspaceFolders[0].uri.fsPath, '.CodeReDesignWorkSpace'); // 替换为你的子文件夹名称 |
50 | 18 |
|
51 | | -## FILE:k:\lab\CodeReDesign-dummy\src\deepseekApi.ts |
52 | | -## OPERATION:INSERT |
53 | | -## BEFORE_ANCHOR |
54 | | -```typescript |
55 | | - fs.writeFileSync(newCvbFilePath, cvb.toString(), 'utf-8'); |
56 | | - vscode.window.showInformationMessage(`API response saved as CVB file: ${newCvbFilePath}`); |
57 | | -``` |
58 | | -## AFTER_ANCHOR |
59 | | -```typescript |
60 | | - } |
61 | | - clearCurrentOperationController(); |
| 19 | + // 创建文件系统监听器 |
62 | 20 | ``` |
63 | 21 | ## INSERT_CONTENT |
64 | 22 | ```typescript |
65 | | - // 保存原始TCVB内容 |
66 | | - const tcvbFilePath = path.join(tmpDir, fileName.replace(/\.cvb$/, '.tcvb')); |
67 | | - fs.writeFileSync(tcvbFilePath, apiResponse, 'utf-8'); |
68 | | -``` |
| 23 | + // 监听 .tcvb 和 .md 文件变化 |
| 24 | + const markdownWatcher = vscode.workspace.createFileSystemWatcher( |
| 25 | + new vscode.RelativePattern(targetFolder, '**/*.md') |
| 26 | + ); |
69 | 27 |
|
70 | | -## OPERATION:INSERT |
71 | | -## BEFORE_ANCHOR |
72 | | -```typescript |
73 | | - if (analysisResult) { |
74 | | - vscode.window.showInformationMessage('Analysis completed. Check the output channel for details.'); |
75 | | -``` |
76 | | -## AFTER_ANCHOR |
77 | | -```typescript |
78 | | - } |
79 | | - clearCurrentOperationController(); |
80 | | -``` |
81 | | -## INSERT_CONTENT |
82 | | -```typescript |
83 | | - // 保存分析结果到Markdown |
84 | | - const mdFileName = path.basename(filePath).replace(/\.cvb$/, '_analysis.md'); |
85 | | - const mdFilePath = path.join(path.dirname(filePath), mdFileName); |
86 | | - fs.writeFileSync(mdFilePath, `# Analysis Report\n\n${analysisResult}`, 'utf-8'); |
| 28 | + const tcvbWatcher = vscode.workspace.createFileSystemWatcher( |
| 29 | + new vscode.RelativePattern(targetFolder, '**/*.tcvb') |
| 30 | + ); |
| 31 | + |
| 32 | + // 当文件变化时刷新视图 |
| 33 | + markdownWatcher.onDidCreate(() => cvbViewProvider.refresh()); |
| 34 | + markdownWatcher.onDidDelete(() => cvbViewProvider.refresh()); |
| 35 | + markdownWatcher.onDidChange(() => cvvViewProvider.refresh()); |
| 36 | + |
| 37 | + tcvbWatcher.onDidCreate(() => cvbViewProvider.refresh()); |
| 38 | + tcvbWatcher.onDidDelete(() => cvbViewProvider.refresh()); |
| 39 | + tcvbWatcher.onDidChange(() => cvbViewProvider.refresh()); |
| 40 | + |
| 41 | + // 将监听器添加到订阅中,确保扩展销毁时清理资源 |
| 42 | + context.subscriptions.push(markdownWatcher, tcvbWatcher); |
| 43 | + } |
87 | 44 | ``` |
88 | 45 |
|
89 | | -## FILE:k:\lab\CodeReDesign-dummy\src\cvbManager.ts |
| 46 | +## FILE:k:\lab\CodeReDesign-dummy\src\deepseekApi.ts |
90 | 47 | ## OPERATION:INSERT |
91 | 48 | ## BEFORE_ANCHOR |
92 | 49 | ```typescript |
93 | | -class CvbFile extends vscode.TreeItem { |
94 | | - constructor( |
95 | | - public readonly label: string, |
96 | | - public readonly uri: vscode.Uri |
97 | | - ) { |
| 50 | + if (apiResponse) { |
| 51 | + apiResponse = apiResponse.replace(/\r\n?/g, "\n"); |
| 52 | + const tcvb = new TCVB(apiResponse); |
98 | 53 | ``` |
99 | 54 | ## AFTER_ANCHOR |
100 | 55 | ```typescript |
101 | | - // 设置图标(可选) |
102 | | - this.iconPath = vscode.ThemeIcon.File; |
| 56 | + cvb.setMetaData("用户需求", userPrompt); |
| 57 | + const newCvbFilePath = path.join(tmpDir, fileName); |
| 58 | + fs.writeFileSync(newCvbFilePath, cvb.toString(), 'utf-8'); |
103 | 59 | ``` |
104 | 60 | ## INSERT_CONTENT |
105 | 61 | ```typescript |
106 | | - // 根据文件类型设置不同图标 |
107 | | - if (uri.fsPath.endsWith('.tcvb')) { |
108 | | - this.iconPath = new vscode.ThemeIcon('diff'); |
109 | | - } else if (uri.fsPath.endsWith('.md')) { |
110 | | - this.iconPath = new vscode.ThemeIcon('markdown'); |
111 | | - } |
| 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'); |
112 | 69 | ``` |
113 | 70 |
|
114 | 71 | ## END_TCVB |
115 | | - |
116 | | -这个TCVB实现了: |
117 | | -1. 在侧边栏增加.tcvb和.md文件支持 |
118 | | -2. 上传TCVB时保存原始TCVB文件 |
119 | | -3. 分析结果保存为Markdown文件 |
120 | | -4. 不同文件类型显示不同图标 |
121 | | -5. 文件名保持与CVB文件一致(自动替换扩展名) |
122 | | - |
123 | | -所有修改都保持原有功能完整,新增文件会在.CodReDesignWorkSpace目录生成,并能在侧边栏正确显示和操作。 |
| 72 | +``` |
0 commit comments