Skip to content

Commit 3e1cb30

Browse files
committed
Remove unnecessary comments and optimize file sorting logic for context collection
1 parent 80c2d70 commit 3e1cb30

5 files changed

Lines changed: 14 additions & 18 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ export const context_initialization = async (
462462
tab_change_timeout = setTimeout(() => {
463463
update_view_badges()
464464
tab_change_timeout = null
465-
}, 100) // 100ms debounce
465+
}, 100)
466466
})
467467
)
468468

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export class OpenEditorsProvider
183183

184184
const token_count = element.tokenCount
185185

186-
let final_description = element.description || '' // relative path
186+
let final_description = element.description || ''
187187

188188
const prefix_parts: string[] = []
189189
if (token_count !== undefined) {
@@ -297,7 +297,7 @@ export class OpenEditorsProvider
297297
false,
298298
true,
299299
token_count,
300-
undefined, // selectedTokenCount is undefined for open editor files
300+
undefined,
301301
description,
302302
false,
303303
range

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ export class WorkspaceProvider
992992
} else {
993993
this._checked_timestamps.delete(key)
994994
}
995-
this._token_calculator.invalidate_directory_selected_count(key) // Invalidate self
995+
this._token_calculator.invalidate_directory_selected_count(key)
996996

997997
if (item.isDirectory) {
998998
await this._update_directory_check_state(key, state, false)
@@ -1001,7 +1001,7 @@ export class WorkspaceProvider
10011001
let dir_path = path.dirname(key)
10021002
const workspace_root = this.get_workspace_root_for_file(key)
10031003
while (workspace_root && dir_path.startsWith(workspace_root)) {
1004-
this._token_calculator.invalidate_directory_selected_count(dir_path) // Invalidate parents
1004+
this._token_calculator.invalidate_directory_selected_count(dir_path)
10051005
await this._update_parent_state(dir_path)
10061006
dir_path = path.dirname(dir_path)
10071007
}
@@ -1011,7 +1011,7 @@ export class WorkspaceProvider
10111011
}
10121012

10131013
private async _update_parent_state(dir_path: string): Promise<void> {
1014-
this._token_calculator.invalidate_directory_selected_count(dir_path) // Invalidate selected count for this dir
1014+
this._token_calculator.invalidate_directory_selected_count(dir_path)
10151015
try {
10161016
const workspace_root = this.get_workspace_root_for_file(dir_path)
10171017
if (!workspace_root) return
@@ -1299,7 +1299,7 @@ export class WorkspaceProvider
12991299
const gitignore_files = await vscode.workspace.findFiles(
13001300
'**/{.gitignore,.cursorignore,.codeiumignore}'
13011301
)
1302-
this._combined_gitignore = ignore() // Reset
1302+
this._combined_gitignore = ignore()
13031303

13041304
for (const file_uri of gitignore_files) {
13051305
const gitignore_path = file_uri.fsPath

‎packages/vscode/src/context/shared-file-state.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ export class SharedFileState {
176176
return false
177177
}
178178

179-
// Get all currently open editor URIs
180179
private get_open_editor_uris(): vscode.Uri[] {
181180
const open_uris: vscode.Uri[] = []
182181
vscode.window.tabGroups.all.forEach((group) => {
@@ -189,7 +188,6 @@ export class SharedFileState {
189188
return open_uris
190189
}
191190

192-
// Update a file check state in open editors
193191
private async update_file_in_open_editors(
194192
file_path: string,
195193
checked: boolean

‎packages/vscode/src/utils/files-collector.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ export class FilesCollector {
131131
now: number,
132132
three_hours: number
133133
): string[] {
134-
// Categorize files into two groups
135134
const recently_modified: Array<{ path: string; mtime: number }> = []
136135
const older_files: Array<{ path: string; timestamp: number }> = []
137136

@@ -146,10 +145,8 @@ export class FilesCollector {
146145
this.workspace_provider.get_selection_timestamp(file_path) ?? now
147146

148147
if (now - mtime < three_hours) {
149-
// Modified within last 3 hours
150148
recently_modified.push({ path: file_path, mtime })
151149
} else {
152-
// Modified earlier than 3 hours
153150
older_files.push({ path: file_path, timestamp: selection_timestamp })
154151
}
155152
} catch (error) {
@@ -158,19 +155,20 @@ export class FilesCollector {
158155
}
159156

160157
// Sort older files by selection timestamp (ascending), with natural sort as tiebreaker
158+
// Files selected within 20 seconds of each other are grouped and sorted naturally
161159
older_files.sort((a, b) => {
162-
const timestamp_diff = a.timestamp - b.timestamp
163-
if (timestamp_diff != 0) {
164-
return timestamp_diff
160+
const timestamp_bucket_a = Math.floor(a.timestamp / 20)
161+
const timestamp_bucket_b = Math.floor(b.timestamp / 20)
162+
const bucket_diff = timestamp_bucket_a - timestamp_bucket_b
163+
if (bucket_diff != 0) {
164+
return bucket_diff
165165
}
166-
// If timestamps are the same, use natural sort on paths
166+
// If timestamps are within the same 20-second bucket, use natural sort on paths
167167
return natural_sort(a.path, b.path)
168168
})
169169

170-
// Sort recently modified files by modification time (ascending - oldest to newest)
171170
recently_modified.sort((a, b) => a.mtime - b.mtime)
172171

173-
// Combine: older files first, then recently modified
174172
return [
175173
...older_files.map((f) => f.path),
176174
...recently_modified.map((f) => f.path)

0 commit comments

Comments
 (0)