Skip to content

Commit c8ce7be

Browse files
committed
Make clear_checks async and optimize parent state updates with batch processing
1 parent 518f5e9 commit c8ce7be

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

packages/vscode/src/context/context-initialization.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ export const context_initialization = async (
345345
register_workspace_view_handlers(workspace_view)
346346
context.subscriptions.push(workspace_view)
347347
}),
348-
vscode.commands.registerCommand('codeWebChat.clearChecks', () => {
349-
workspace_provider!.clear_checks()
348+
vscode.commands.registerCommand('codeWebChat.clearChecks', async () => {
349+
await workspace_provider!.clear_checks()
350350
}),
351351
vscode.commands.registerCommand('codeWebChat.checkAll', async () => {
352352
await workspace_provider!.check_all()

packages/vscode/src/context/providers/workspace-provider.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ export class WorkspaceProvider
410410
this.refresh_timeout = null
411411
}, 1000) // Debounce refresh to handle bulk file changes like builds
412412
}
413-
public clear_checks(): void {
413+
public async clear_checks(): Promise<void> {
414414
const config = vscode.workspace.getConfiguration('codeWebChat')
415415
const clear_checks_in_workspace_behavior = config.get<string>(
416416
'clearChecksInWorkspaceBehavior'
@@ -447,17 +447,27 @@ export class WorkspaceProvider
447447
this.partially_checked_dirs.clear()
448448
this.directory_selected_token_counts.clear()
449449

450+
const dirs_to_update = new Set<string>()
451+
450452
for (const file_path of open_files) {
451453
if (this.checked_items.has(file_path)) {
452454
let dir_path = path.dirname(file_path)
453455
const workspace_root = this.get_workspace_root_for_file(file_path)
454456
while (workspace_root && dir_path.startsWith(workspace_root)) {
455-
this._update_parent_state(dir_path)
457+
dirs_to_update.add(dir_path)
456458
dir_path = path.dirname(dir_path)
457459
}
458460
}
459461
}
460462

463+
const sorted_dirs = Array.from(dirs_to_update).sort(
464+
(a, b) => b.length - a.length
465+
)
466+
467+
for (const dir_path of sorted_dirs) {
468+
await this._update_parent_state(dir_path)
469+
}
470+
461471
if (checked_open_files.length > 0) {
462472
vscode.window
463473
.showInformationMessage(

0 commit comments

Comments
 (0)