11import * as vscode from 'vscode' ;
22import * as path from 'path' ;
33import * as fs from 'fs' ;
4- import { applyCvbToWorkspace } from './cvbManager' ;
4+ import { applyCvbToWorkspace } from './cvbManager' ;
5+ import { queryCodeReDesign , analyzeCode } from './deepseekApi' ;
56
67export function registerCvbContextMenu ( context : vscode . ExtensionContext ) {
78
@@ -11,11 +12,23 @@ export function registerCvbContextMenu(context: vscode.ExtensionContext) {
1112 const filePath = uri . fsPath ;
1213
1314 // 调用处理函数
14- applyCvb ( filePath ) ;
15+ applyThisCvb ( filePath ) ;
16+ } ) ;
17+
18+ // 注册上传 CVB 命令
19+ const uploadCvbCommand = vscode . commands . registerCommand ( 'codeReDesign.uploadThisCvb' , async ( uri : vscode . Uri ) => {
20+ const filePath = uri . fsPath ;
21+ await uploadThisCvb ( filePath ) ;
22+ } ) ;
23+
24+ // 注册分析 CVB 命令
25+ const analyzeCvbCommand = vscode . commands . registerCommand ( 'codeReDesign.analyzeThisCvb' , async ( uri : vscode . Uri ) => {
26+ const filePath = uri . fsPath ;
27+ await analyzeThisCvb ( filePath ) ;
1528 } ) ;
1629
1730 // 将命令添加到订阅中
18- context . subscriptions . push ( applyCvbCommand ) ;
31+ context . subscriptions . push ( applyCvbCommand , uploadCvbCommand , analyzeCvbCommand ) ;
1932
2033 // 注册 TreeDataProvider
2134 const cvbViewProvider = new CvbViewProvider ( ) ;
@@ -122,7 +135,7 @@ class CvbFile extends vscode.TreeItem {
122135 * 处理 .cvb 文件的函数
123136 * @param filePath .cvb 文件的路径
124137 */
125- function applyCvb ( filePath : string ) {
138+ function applyThisCvb ( filePath : string ) {
126139 // 在这里实现你的逻辑
127140 vscode . window . showInformationMessage ( `Applying CVB from: ${ filePath } ` ) ;
128141 // 例如:读取文件内容并处理
@@ -135,4 +148,50 @@ function applyCvb(filePath: string) {
135148 }
136149}
137150
151+ /**
152+ * 上传 CVB 文件并调用 API
153+ * @param filePath .cvb 文件的路径
154+ */
155+ async function uploadThisCvb ( filePath : string ) {
156+ const userPrompt = await vscode . window . showInputBox ( {
157+ prompt : 'Enter your prompt for the refactoring' ,
158+ placeHolder : 'e.g., Refactor the code to improve readability' ,
159+ } ) ;
160+
161+ if ( ! userPrompt ) {
162+ return ;
163+ }
164+
165+ const cvbContent = fs . readFileSync ( filePath , 'utf-8' ) ;
166+ const outputChannel = vscode . window . createOutputChannel ( 'CodeReDesign API Stream' ) ;
167+
168+ const apiResponse = await queryCodeReDesign ( cvbContent , userPrompt , outputChannel ) ;
169+ if ( apiResponse ) {
170+ vscode . window . showInformationMessage ( 'API response received. Check the output channel for details.' ) ;
171+ }
172+ }
173+
174+ /**
175+ * 分析 CVB 文件
176+ * @param filePath .cvb 文件的路径
177+ */
178+ async function analyzeThisCvb ( filePath : string ) {
179+ const userRequest = await vscode . window . showInputBox ( {
180+ prompt : 'Enter your analysis request' ,
181+ placeHolder : 'e.g., Analyze the code for potential bugs' ,
182+ } ) ;
183+
184+ if ( ! userRequest ) {
185+ return ;
186+ }
187+
188+ const cvbContent = fs . readFileSync ( filePath , 'utf-8' ) ;
189+ const outputChannel = vscode . window . createOutputChannel ( 'CodeReDesign API Stream' ) ;
190+
191+ const analysisResult = await analyzeCode ( cvbContent , userRequest , outputChannel ) ;
192+ if ( analysisResult ) {
193+ vscode . window . showInformationMessage ( 'Analysis completed. Check the output channel for details.' ) ;
194+ }
195+ }
196+
138197export function deactivate ( ) { }
0 commit comments