@@ -364,62 +364,97 @@ export class WorkspaceProvider
364364 }
365365
366366 private _on_file_system_changed ( changed_file_path ?: string ) : void {
367- if ( changed_file_path ) {
368- this . file_token_counts . delete ( changed_file_path )
367+ if ( ! changed_file_path ) return
369368
370- let dir_path = path . dirname ( changed_file_path )
371- const workspace_root = this . get_workspace_root_for_file ( changed_file_path )
369+ const workspace_root = this . get_workspace_root_for_file ( changed_file_path )
370+ if ( ! workspace_root ) return
372371
373- while ( workspace_root && dir_path . startsWith ( workspace_root ) ) {
374- this . directory_token_counts . delete ( dir_path )
375- this . directory_selected_token_counts . delete ( dir_path )
376- dir_path = path . dirname ( dir_path )
372+ if ( path . basename ( changed_file_path ) == '.gitignore' ) return
373+
374+ this . file_token_counts . delete ( changed_file_path )
375+
376+ let dir_path = path . dirname ( changed_file_path )
377+ while ( dir_path . startsWith ( workspace_root ) ) {
378+ this . directory_token_counts . delete ( dir_path )
379+ this . directory_selected_token_counts . delete ( dir_path )
380+ dir_path = path . dirname ( dir_path )
381+ }
382+
383+ if ( ! fs . existsSync ( changed_file_path ) ) {
384+ this . file_workspace_map . delete ( changed_file_path )
385+ this . checked_items . delete ( changed_file_path )
386+ this . partially_checked_dirs . delete ( changed_file_path )
387+
388+ let parent_dir = path . dirname ( changed_file_path )
389+ while ( parent_dir . startsWith ( workspace_root ) ) {
390+ this . _update_parent_state ( parent_dir )
391+ parent_dir = path . dirname ( parent_dir )
377392 }
378- } else {
379- // If no specific file path provided, clear all caches (fallback)
380- this . file_token_counts . clear ( )
381- this . directory_token_counts . clear ( )
382- this . directory_selected_token_counts . clear ( )
393+
394+ this . _on_did_change_checked_files . fire ( )
383395 }
384396
385397 this . _schedule_refresh ( )
386398 }
387399
388400 private async _handle_file_create ( created_file_path ?: string ) : Promise < void > {
389- if ( created_file_path ) {
390- if ( ! should_ignore_file ( created_file_path , this . ignored_extensions ) ) {
391- this . checked_items . set (
392- created_file_path ,
393- vscode . TreeItemCheckboxState . Checked
394- )
395- let dir_path = path . dirname ( created_file_path )
396- const workspace_root =
397- this . get_workspace_root_for_file ( created_file_path )
398- while ( workspace_root && dir_path . startsWith ( workspace_root ) ) {
401+ if ( ! created_file_path ) return
402+
403+ const workspace_root = this . get_workspace_root_for_file ( created_file_path )
404+ if ( ! workspace_root ) return
405+
406+ if ( path . basename ( created_file_path ) == '.gitignore' ) return
407+
408+ this . file_workspace_map . set ( created_file_path , workspace_root )
409+
410+ const parent_dir = path . dirname ( created_file_path )
411+ const parent_state = this . checked_items . get ( parent_dir )
412+
413+ if ( parent_state === vscode . TreeItemCheckboxState . Checked ) {
414+ const relative_path = path . relative ( workspace_root , created_file_path )
415+
416+ if (
417+ ! this . is_excluded ( relative_path ) &&
418+ ! should_ignore_file ( created_file_path , this . ignored_extensions )
419+ ) {
420+ const is_directory = fs . statSync ( created_file_path ) . isDirectory ( )
421+
422+ if ( is_directory ) {
423+ this . checked_items . set (
424+ created_file_path ,
425+ vscode . TreeItemCheckboxState . Checked
426+ )
427+ await this . _update_directory_check_state (
428+ created_file_path ,
429+ vscode . TreeItemCheckboxState . Checked ,
430+ false
431+ )
432+ } else {
433+ this . checked_items . set (
434+ created_file_path ,
435+ vscode . TreeItemCheckboxState . Checked
436+ )
437+ }
438+
439+ let dir_path = parent_dir
440+ while ( dir_path . startsWith ( workspace_root ) ) {
441+ this . directory_selected_token_counts . delete ( dir_path )
399442 await this . _update_parent_state ( dir_path )
400443 dir_path = path . dirname ( dir_path )
401444 }
445+
402446 this . _on_did_change_checked_files . fire ( )
403447 }
448+ }
404449
405- this . file_token_counts . delete ( created_file_path )
406-
407- let dir_path = path . dirname ( created_file_path )
408- const workspace_root = this . get_workspace_root_for_file ( created_file_path )
409-
410- while ( workspace_root && dir_path . startsWith ( workspace_root ) ) {
411- this . directory_token_counts . delete ( dir_path )
412- this . directory_selected_token_counts . delete ( dir_path )
413- dir_path = path . dirname ( dir_path )
414- }
415- } else {
416- // If no specific file path provided, clear all caches (fallback)
417- this . file_token_counts . clear ( )
418- this . directory_token_counts . clear ( )
419- this . directory_selected_token_counts . clear ( )
450+ let dir_path = parent_dir
451+ while ( dir_path . startsWith ( workspace_root ) ) {
452+ this . directory_token_counts . delete ( dir_path )
453+ this . directory_selected_token_counts . delete ( dir_path )
454+ dir_path = path . dirname ( dir_path )
420455 }
421456
422- this . _on_file_system_changed ( created_file_path )
457+ this . _schedule_refresh ( )
423458 }
424459
425460 public refresh ( ) : void {
@@ -437,7 +472,7 @@ export class WorkspaceProvider
437472 this . refresh_timeout = setTimeout ( ( ) => {
438473 this . _on_did_change_tree_data . fire ( )
439474 this . refresh_timeout = null
440- } , 500 ) // Debounce refresh to handle bulk file changes like builds
475+ } , 1000 ) // Debounce refresh to handle bulk file changes like builds
441476 }
442477 public clear_checks ( ) : void {
443478 this . websites_provider . clear_checks ( )
0 commit comments