@@ -7,7 +7,6 @@ import * as os from 'os';
77// Command IDs
88const SHOW_DEPENDENCY_GRAPH = 'bibimbob.showDependencyGraph' ;
99const FOCUS_MODULE_DEPENDENCIES = 'bibimbob.focusModuleDependencies' ;
10- const CLEAR_CACHE = 'bibimbob.clearCache' ;
1110
1211// Track the current webview panel
1312let currentPanel : vscode . WebviewPanel | undefined = undefined ;
@@ -24,54 +23,8 @@ export function activate(context: vscode.ExtensionContext) {
2423 await generateDependencyGraph ( context , true ) ;
2524 } ) ;
2625
27- // Command to clear the rescriptdep cache
28- let clearCacheCommand = vscode . commands . registerCommand ( CLEAR_CACHE , async ( ) => {
29- await clearRescriptDepCache ( context ) ;
30- } ) ;
31-
3226 context . subscriptions . push ( fullGraphCommand ) ;
3327 context . subscriptions . push ( focusModuleCommand ) ;
34- context . subscriptions . push ( clearCacheCommand ) ;
35- }
36-
37- // Function to clear the rescriptdep cache
38- async function clearRescriptDepCache ( context : vscode . ExtensionContext ) : Promise < void > {
39- return vscode . window . withProgress ( {
40- location : vscode . ProgressLocation . Notification ,
41- title : 'ReScript: Clearing dependency cache...' ,
42- cancellable : false
43- } , async ( progress ) => {
44- try {
45- // Get cache directory using globalStorageUri instead of globalStoragePath
46- const cacheDir = vscode . Uri . joinPath ( context . globalStorageUri , 'cache' ) ;
47- const cacheDirPath = cacheDir . fsPath ;
48-
49- if ( fs . existsSync ( cacheDirPath ) ) {
50- // Read all files in the cache directory
51- const files = fs . readdirSync ( cacheDirPath ) ;
52-
53- // Delete all cache files
54- let deletedCount = 0 ;
55- for ( const file of files ) {
56- if ( file . endsWith ( '.rescriptdep_cache.marshal' ) ) {
57- fs . unlinkSync ( path . join ( cacheDirPath , file ) ) ;
58- deletedCount ++ ;
59- }
60- }
61-
62- if ( deletedCount > 0 ) {
63- vscode . window . showInformationMessage ( `ReScript Dependency: Cleared ${ deletedCount } cache file(s)` ) ;
64- } else {
65- vscode . window . showInformationMessage ( 'No ReScript dependency cache files found' ) ;
66- }
67- } else {
68- vscode . window . showInformationMessage ( 'No ReScript dependency cache directory found' ) ;
69- }
70- } catch ( error ) {
71- console . error ( 'Error clearing cache:' , error ) ;
72- vscode . window . showErrorMessage ( `Failed to clear cache: ${ error instanceof Error ? error . message : String ( error ) } ` ) ;
73- }
74- } ) ;
7528}
7629
7730// Helper function to get current module name from active editor
@@ -315,13 +268,19 @@ async function generateDependencyGraph(context: vscode.ExtensionContext, focusOn
315268 progress . report ( { message : 'Running rescriptdep CLI...' } ) ;
316269 if ( token . isCancellationRequested ) return ;
317270
318- const cliArgs = [
319- '--format=json' ,
320- ...( moduleName ? [ '--module' , moduleName ] : [ ] ) ,
321- bsDir // Use the bsDir calculated based on focus mode
322- ] ;
271+ // Define CLI arguments
272+ const args : string [ ] = [ '--format=json' ] ;
323273
324- const jsonContent = await runRescriptDep ( cliPath , cliArgs , context ) ;
274+ // Add module focus if specified
275+ if ( moduleName ) {
276+ args . push ( '--module' , moduleName ) ;
277+ }
278+
279+ // Add bsDir target
280+ args . push ( bsDir ) ;
281+
282+ // Get JSON format data
283+ const jsonContent = await runRescriptDep ( cliPath , args , context ) ;
325284
326285 // Display webview
327286 progress . report ( { message : 'Generating visualization...' } ) ;
@@ -1249,32 +1208,19 @@ function showGraphWebview(context: vscode.ExtensionContext, jsonContent: string,
12491208 // Find CLI path
12501209 const cliPath = await findRescriptDepCLI ( context ) ;
12511210
1252- // Setup cache args (requires context)
1253- let cacheArgs : string [ ] = [ ] ;
1254- if ( context ) {
1255- try {
1256- const cacheDir = vscode . Uri . joinPath ( context . globalStorageUri , 'cache' ) ;
1257- const cacheDirPath = cacheDir . fsPath ;
1258- const storageDir = context . globalStorageUri . fsPath ;
1259- if ( ! fs . existsSync ( storageDir ) ) fs . mkdirSync ( storageDir , { recursive : true } ) ;
1260- if ( ! fs . existsSync ( cacheDirPath ) ) fs . mkdirSync ( cacheDirPath , { recursive : true } ) ;
1261- const workspaceName = vscode . workspace . workspaceFolders ?. [ 0 ] ?. name || 'default' ;
1262- const cacheFilePath = path . join ( cacheDirPath , `${ workspaceName } .rescriptdep_cache.marshal` ) ;
1263- cacheArgs = [ '--cache-file' , cacheFilePath ] ;
1264- } catch ( error ) { console . error ( 'Error setting up cache dir for focus:' , error ) ; }
1211+ // Define CLI arguments
1212+ const args : string [ ] = [ '--format=json' ] ;
1213+
1214+ // Add module focus if specified
1215+ if ( moduleName ) {
1216+ args . push ( '--module' , moduleName ) ;
12651217 }
12661218
1267- // Define the core arguments for the CLI
1268- const coreArgs = [
1269- '--format=json' ,
1270- '--module' ,
1271- moduleName ,
1272- bsDir
1273- ] ;
1274- const fullArgs = [ ...cacheArgs , ...coreArgs ] ;
1219+ // Add bsDir target
1220+ args . push ( bsDir ) ;
12751221
12761222 // Get JSON format data
1277- const jsonContent = await runRescriptDep ( cliPath , fullArgs , context ) ;
1223+ const jsonContent = await runRescriptDep ( cliPath , args , context ) ;
12781224
12791225 if ( token . isCancellationRequested ) return ;
12801226
0 commit comments