11import * as vscode from 'vscode' ;
22import * as path from 'path' ;
33import * as fs from 'fs' ;
4- import { applyCvbToWorkspace } from './cvbManager' ;
5- import { queryCodeReDesign , analyzeCode } from './deepseekApi' ;
4+ import { applyCvbToWorkspace , generateTimestamp , parseCvb } from './cvbManager' ;
5+ import { queryCodeReDesign , analyzeCode , generateFilenameFromRequest } from './deepseekApi' ;
66import { getCurrentOperationController , resetCurrentOperationController , clearCurrentOperationController } from './extension' ;
77
88export function registerCvbContextMenu ( context : vscode . ExtensionContext ) {
@@ -169,6 +169,24 @@ async function uploadThisCvb(filePath: string) {
169169 return ;
170170 }
171171
172+ const workspaceFolders = vscode . workspace . workspaceFolders ;
173+ if ( ! workspaceFolders ) {
174+ vscode . window . showErrorMessage ( 'No workspace folder found.' ) ;
175+ return ;
176+ }
177+ const workspacePath = workspaceFolders [ 0 ] . uri . fsPath ;
178+ const tmpDir = path . join ( workspacePath , '.CodeReDesignWorkSpace' ) ;
179+
180+ const filenameSummary = await generateFilenameFromRequest ( userPrompt ) ;
181+ const timestamp = generateTimestamp ( ) ;
182+ let baseFileName = `${ timestamp } _${ filenameSummary } .cvb` ;
183+ let fileName = baseFileName ;
184+ let i = 1 ;
185+ while ( fs . existsSync ( path . join ( tmpDir , fileName ) ) ) {
186+ fileName = `${ timestamp } _${ filenameSummary } _${ i } .cvb` ;
187+ i ++ ;
188+ }
189+
172190 const cvbContent = fs . readFileSync ( filePath , 'utf-8' ) ;
173191 const outputChannel = vscode . window . createOutputChannel ( 'CodeReDesign API Stream' ) ;
174192
@@ -178,6 +196,12 @@ async function uploadThisCvb(filePath: string) {
178196 if ( apiResponse ) {
179197 vscode . window . showInformationMessage ( 'API response received. Check the output channel for details.' ) ;
180198 }
199+ if ( apiResponse ) {
200+ const { cvbContent : newCvbContent , metadata, files } = parseCvb ( apiResponse ) ;
201+ const newCvbFilePath = path . join ( tmpDir , fileName ) ;
202+ fs . writeFileSync ( newCvbFilePath , newCvbContent , 'utf-8' ) ;
203+ vscode . window . showInformationMessage ( `API response saved as CVB file: ${ newCvbFilePath } ` ) ;
204+ }
181205 clearCurrentOperationController ( ) ;
182206}
183207
0 commit comments