11import * as vscode from 'vscode' ;
22import * as path from 'path' ;
33import * as fs from 'fs' ;
4- import { applyCvbToWorkspace } from './cvbManager' ;
4+ import { applyCvbToWorkspace , compressCvb , Cvb } from './cvbManager' ;
55import { analyzeCode } from './deepseekApi' ;
66import { getCurrentOperationController , resetCurrentOperationController , clearCurrentOperationController , doUploadCommand , saveAnalyzeCodeResult } from './extension' ;
77import { showInputMultiLineBox } from './UIComponents' ;
@@ -74,6 +74,12 @@ export function registerCvbContextMenu(context: vscode.ExtensionContext) {
7474 await analyzeThisCvb ( filePath ) ;
7575 } ) ;
7676
77+ // 注册分析 CVB 命令
78+ const compressCvbCommand = vscode . commands . registerCommand ( 'codeReDesign.compressThisCvb' , async ( cvb : CvbFile ) => {
79+ const filePath = cvb . resourceUri ?. fsPath || "" ;
80+ await compressThisCvb ( filePath ) ;
81+ } ) ;
82+
7783 // 将命令添加到订阅中
7884 context . subscriptions . push ( applyCvbCommand , uploadCvbCommand , analyzeCvbCommand ) ;
7985
@@ -319,7 +325,7 @@ async function uploadThisCvb(filePath: string) {
319325 // 测试 end
320326*/
321327 const userPrompt = await showInputMultiLineBox ( {
322- prompt : 'Enter your prompt for the refactoring ' ,
328+ prompt : '输入你的重构方案 ' ,
323329 placeHolder : 'e.g., Refactor the code to improve readability' ,
324330 } ) ;
325331
@@ -336,7 +342,7 @@ async function uploadThisCvb(filePath: string) {
336342 */
337343async function analyzeThisCvb ( filePath : string ) {
338344 const userRequest = await showInputMultiLineBox ( {
339- prompt : 'Enter your analysis request ' ,
345+ prompt : '输入你的分析需求 ' ,
340346 placeHolder : 'e.g., Analyze the code for potential bugs' ,
341347 } ) ;
342348
@@ -360,4 +366,47 @@ async function analyzeThisCvb(filePath: string) {
360366 }
361367}
362368
369+ function getCompressedFileName ( filePath : string ) : string {
370+ const { name, ext } = path . parse ( filePath ) ; // 使用 path.parse 获取文件名和扩展名
371+ return path . join ( path . dirname ( filePath ) , `${ name } -compress${ ext } ` ) ; // 拼接新的完整路径
372+ }
373+
374+ /**
375+ * 分析 CVB 文件
376+ * @param filePath .cvb 文件的路径
377+ */
378+ async function compressThisCvb ( filePath : string ) {
379+ const userRequest = await showInputMultiLineBox ( {
380+ prompt : '输入压缩过程中需要关注的需求' ,
381+ placeHolder : 'e.g., Analyze the code for potential bugs' ,
382+ } ) ;
383+
384+ if ( ! userRequest ) {
385+ return ;
386+ }
387+
388+ const cvbContent = fs . readFileSync ( filePath , 'utf-8' ) ;
389+
390+ const cvb = new Cvb ( cvbContent ) ;
391+
392+ resetCurrentOperationController ( ) ;
393+
394+ const newCvb = await compressCvb ( cvb , userRequest ) ;
395+ clearCurrentOperationController ( ) ;
396+
397+ if ( newCvb ) {
398+ vscode . window . showInformationMessage ( 'compress cvb success!.' ) ;
399+ }
400+ else {
401+ vscode . window . showInformationMessage ( 'compress cvb failed!.' ) ;
402+ return ;
403+ }
404+
405+ newCvb . setMetaData ( "comressFrom" , filePath ) ;
406+ filePath = getCompressedFileName ( filePath ) ;
407+
408+ fs . writeFileSync ( filePath , newCvb . toString ( ) , 'utf-8' ) ;
409+ vscode . window . showInformationMessage ( `Conversation log saved as: ${ filePath } ` ) ;
410+ }
411+
363412export function deactivate ( ) { }
0 commit comments