Skip to content

Commit a0adae3

Browse files
committed
Update UI messages and debounce change events in workspace and open editors providers
1 parent ae1df0d commit a0adae3

3 files changed

Lines changed: 45 additions & 28 deletions

File tree

‎packages/shared/src/constants/dictionary.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ export const dictionary = {
145145
TYPE_SOMETHING_TO_USE_GROUP: 'Type something to use this group.',
146146
GROUP_HAS_NO_SELECTED_PRESETS:
147147
'The chosen group has no selected presets to run.',
148-
NO_RECENTLY_USED_PRESETS_OR_GROUPS: 'No recently used presets or groups.',
148+
NO_RECENTLY_USED_PRESETS_OR_GROUPS:
149+
'No recently used presets or groups. Select from list below.',
149150
CHECKPOINT_OPERATION_IN_PROGRESS:
150151
'Another checkpoint operation is currently in progress. Please wait for it to complete.',
151152
URL_OVERRIDE_DIFFERENT_DOMAIN: (preset_name: string) =>

‎packages/vscode/src/context/providers/open-editors/open-editors-provider.ts‎

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class OpenEditorsProvider
3030
private _config_change_handler: vscode.Disposable
3131
private _workspace_provider: WorkspaceProvider
3232
private _use_compact_token_count: boolean = false
33+
private _change_event_dispatch_timeout: NodeJS.Timeout | null = null
3334

3435
public set_use_compact_token_count(use_compact: boolean): void {
3536
if (this._use_compact_token_count != use_compact) {
@@ -83,6 +84,18 @@ export class OpenEditorsProvider
8384
this.refresh()
8485
}
8586

87+
private _dispatch_change_events(): void {
88+
if (this._change_event_dispatch_timeout) {
89+
clearTimeout(this._change_event_dispatch_timeout)
90+
}
91+
92+
this._change_event_dispatch_timeout = setTimeout(() => {
93+
this._on_did_change_checked_files.fire()
94+
this.refresh()
95+
this._change_event_dispatch_timeout = null
96+
}, 500)
97+
}
98+
8699
private _is_file_in_any_workspace(file_path: string): boolean {
87100
return this._workspace_roots.some((root) => file_path.startsWith(root))
88101
}
@@ -105,7 +118,7 @@ export class OpenEditorsProvider
105118
}
106119

107120
if (files_to_uncheck.length > 0) {
108-
this._on_did_change_checked_files.fire()
121+
this._dispatch_change_events()
109122
}
110123
}
111124

@@ -154,6 +167,9 @@ export class OpenEditorsProvider
154167
this._tab_change_handler.dispose()
155168
this._config_change_handler.dispose()
156169
this._on_did_change_checked_files.dispose()
170+
if (this._change_event_dispatch_timeout) {
171+
clearTimeout(this._change_event_dispatch_timeout)
172+
}
157173
}
158174

159175
refresh(): void {
@@ -357,8 +373,7 @@ export class OpenEditorsProvider
357373
await this._open_file_in_non_preview_mode(item.resourceUri)
358374
}
359375

360-
this._on_did_change_checked_files.fire()
361-
this.refresh()
376+
this._dispatch_change_events()
362377
}
363378

364379
clear_checks(): void {
@@ -373,11 +388,7 @@ export class OpenEditorsProvider
373388
this._checked_items.set(file_path, vscode.TreeItemCheckboxState.Unchecked)
374389
}
375390

376-
// Fire the event with undefined to force full tree refresh
377-
this._on_did_change_tree_data.fire(undefined)
378-
379-
// Fire the checked files change event to trigger synchronization with workspace view
380-
this._on_did_change_checked_files.fire()
391+
this._dispatch_change_events()
381392
}
382393

383394
async check_all(): Promise<void> {
@@ -397,11 +408,7 @@ export class OpenEditorsProvider
397408
}
398409
}
399410

400-
// Fire the event with undefined to force full tree refresh
401-
this._on_did_change_tree_data.fire(undefined)
402-
403-
// Fire the checked files change event to trigger synchronization with workspace view
404-
this._on_did_change_checked_files.fire()
411+
this._dispatch_change_events()
405412
}
406413

407414
get_checked_files(): string[] {
@@ -431,10 +438,7 @@ export class OpenEditorsProvider
431438
}
432439
}
433440

434-
this.refresh()
435-
436-
// Fire the checked files change event to trigger synchronization
437-
this._on_did_change_checked_files.fire()
441+
this._dispatch_change_events()
438442
}
439443

440444
is_initialized(): boolean {

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class WorkspaceProvider
6565
private _file_workspace_map: Map<string, string> = new Map()
6666
public gitignore_initialization: Promise<void>
6767
public ranges_initialization: Promise<void>
68+
private _change_event_dispatch_timeout: NodeJS.Timeout | null = null
6869

6970
private _use_compact_token_count: boolean = false
7071

@@ -184,6 +185,18 @@ export class WorkspaceProvider
184185
return matching_root
185186
}
186187

188+
private _dispatch_change_events(): void {
189+
if (this._change_event_dispatch_timeout) {
190+
clearTimeout(this._change_event_dispatch_timeout)
191+
}
192+
193+
this._change_event_dispatch_timeout = setTimeout(() => {
194+
this._on_did_change_checked_files.fire()
195+
this.refresh()
196+
this._change_event_dispatch_timeout = null
197+
}, 500)
198+
}
199+
187200
private _uncheck_ignored_files(): void {
188201
const checked_files = this.get_all_checked_paths()
189202

@@ -204,7 +217,7 @@ export class WorkspaceProvider
204217
}
205218

206219
if (files_to_uncheck.length > 0) {
207-
this._on_did_change_checked_files.fire()
220+
this._dispatch_change_events()
208221
}
209222
}
210223

@@ -220,6 +233,9 @@ export class WorkspaceProvider
220233
if (this._refresh_timeout) {
221234
clearTimeout(this._refresh_timeout)
222235
}
236+
if (this._change_event_dispatch_timeout) {
237+
clearTimeout(this._change_event_dispatch_timeout)
238+
}
223239

224240
this._token_calculator.dispose()
225241
}
@@ -410,7 +426,7 @@ export class WorkspaceProvider
410426
dir_path = path.dirname(dir_path)
411427
}
412428

413-
this._on_did_change_checked_files.fire()
429+
this._dispatch_change_events()
414430
}
415431

416432
let dir_path = parent_dir
@@ -521,8 +537,7 @@ export class WorkspaceProvider
521537
})
522538
}
523539
}
524-
this.refresh()
525-
this._on_did_change_checked_files.fire()
540+
this._dispatch_change_events()
526541
}
527542

528543
async getTreeItem(element: FileItem): Promise<vscode.TreeItem> {
@@ -1031,8 +1046,7 @@ export class WorkspaceProvider
10311046
dir_path = path.dirname(dir_path)
10321047
}
10331048

1034-
this._on_did_change_checked_files.fire()
1035-
this.refresh()
1049+
this._dispatch_change_events()
10361050
}
10371051

10381052
private async _update_parent_state(dir_path: string): Promise<void> {
@@ -1315,8 +1329,7 @@ export class WorkspaceProvider
13151329
}
13161330
}
13171331

1318-
this.refresh()
1319-
this._on_did_change_checked_files.fire()
1332+
this._dispatch_change_events()
13201333
}
13211334

13221335
// Load .gitignore from all levels of the workspace
@@ -1458,8 +1471,7 @@ export class WorkspaceProvider
14581471
}
14591472
}
14601473

1461-
this.refresh()
1462-
this._on_did_change_checked_files.fire()
1474+
this._dispatch_change_events()
14631475
}
14641476

14651477
public async get_checked_files_token_count(options?: {

0 commit comments

Comments
 (0)