Skip to content

Commit 8032b02

Browse files
committed
Remove selection timestamp tracking and sort older collected files naturally by path
- files should be no longer ordered based on selection timestamp └── apps └── editor └── src ├── commands │ └── duplicate-workspace-command.ts ├── constants │ └── state-keys.ts ├── context │ ├── context-initialization.ts │ └── providers │ └── workspace │ └── workspace-provider.ts ├── utils │ ├── files-collector.ts │ └── natural-sort.ts └── views └── prompt └── backend └── message-handlers └── utils └── build-prompt-payload.ts
1 parent 1fac013 commit 8032b02

5 files changed

Lines changed: 8 additions & 83 deletions

File tree

‎apps/editor/src/commands/duplicate-workspace-command.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export const duplicate_workspace_command = (
3636

3737
const context_to_save: DuplicateWorkspaceContext = {
3838
selected_files: export_state.selected_files,
39-
selected_files_timestamps: export_state.selected_timestamps,
4039
workspace_root_folders,
4140
timestamp: Date.now(),
4241
open_editors

‎apps/editor/src/constants/state-keys.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export const LAST_APPLIED_RAW_INSTRUCTIONS_STATE_KEY =
88
export const LAST_RANGES_SAVE_LOCATION_STATE_KEY = 'last-ranges-save-location'
99
export const LAST_APPLY_CONTEXT_OPTION_STATE_KEY = 'last-apply-context-option'
1010
export const CONTEXT_SELECTED_PATHS_STATE_KEY = 'context-selected-paths'
11-
export const CONTEXT_SELECTED_TIMESTAMPS_STATE_KEY =
12-
'context-selected-timestamps'
1311
export const LAST_SELECTED_SYMBOL_STATE_KEY = 'last-selected-symbol'
1412
export const LAST_SELECTED_CONTEXT_SOURCE_IN_SYMBOLS_QUICK_PICK_STATE_KEY =
1513
'last-selected-context-source-in-symbols-quick-pick'
@@ -138,7 +136,6 @@ export const LAST_COPY_PATHS_FORMAT_STATE_KEY = 'last-copy-paths-format'
138136

139137
export type DuplicateWorkspaceContext = {
140138
selected_files: string[]
141-
selected_files_timestamps: Record<string, number>
142139
timestamp: number
143140
workspace_root_folders: string[]
144141
open_editors?: { path: string; view_column?: number }[]

‎apps/editor/src/context/context-initialization.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { SharedContextState } from './shared-context-state'
88
import { EventEmitter } from 'events'
99
import {
1010
CONTEXT_SELECTED_PATHS_STATE_KEY,
11-
CONTEXT_SELECTED_TIMESTAMPS_STATE_KEY,
1211
DUPLICATE_WORKSPACE_CONTEXT_STATE_KEY,
1312
type DuplicateWorkspaceContext
1413
} from '../constants/state-keys'
@@ -56,11 +55,6 @@ const restore_duplicated_workspace_context = async (
5655
duplicated_context.selected_files
5756
)
5857

59-
await extension_context.workspaceState.update(
60-
CONTEXT_SELECTED_TIMESTAMPS_STATE_KEY,
61-
duplicated_context.selected_files_timestamps
62-
)
63-
6458
if (duplicated_context.open_editors) {
6559
for (const editor_info of duplicated_context.open_editors) {
6660
try {

‎apps/editor/src/context/providers/workspace/workspace-provider.ts‎

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import * as fs from 'fs'
22
import * as path from 'path'
33
import * as vscode from 'vscode'
44
import ignore, { Ignore } from 'ignore'
5-
import {
6-
CONTEXT_SELECTED_PATHS_STATE_KEY,
7-
CONTEXT_SELECTED_TIMESTAMPS_STATE_KEY
8-
} from '@/constants/state-keys'
5+
import { CONTEXT_SELECTED_PATHS_STATE_KEY } from '@/constants/state-keys'
96
import { IGNORED_LOCK_FILES } from '@/constants/ignored-lock-files'
107
import { natural_sort } from '@/utils/natural-sort'
118
import { Logger } from '@shared/utils/logger'
@@ -25,10 +22,8 @@ export interface IWorkspaceProvider {
2522
get_checkbox_state(path: string): vscode.TreeItemCheckboxState
2623
is_partially_selected(path: string): boolean
2724
get_selected_files(): string[]
28-
get_selection_timestamp(path: string): number | undefined
2925
get_export_state(): {
3026
selected_files: string[]
31-
selected_timestamps: Record<string, number>
3227
}
3328
get_all_files_for_uri(uri: vscode.Uri): Promise<vscode.Uri[]>
3429
pause_file_watcher(): void
@@ -53,7 +48,6 @@ export class WorkspaceProvider
5348
private _workspace_names: string[] = []
5449

5550
private _checked_items = new Map<string, vscode.TreeItemCheckboxState>()
56-
private _selected_timestamps = new Map<string, number>()
5751
private _partially_selected_dirs = new Set<string>()
5852

5953
private _combined_gitignore = ignore()
@@ -171,28 +165,18 @@ export class WorkspaceProvider
171165
CONTEXT_SELECTED_PATHS_STATE_KEY,
172166
this.get_all_selected_paths()
173167
)
174-
await this._extension_context.workspaceState.update(
175-
CONTEXT_SELECTED_TIMESTAMPS_STATE_KEY,
176-
Object.fromEntries(this._selected_timestamps)
177-
)
178168
}
179169

180170
load_selected_files_state() {
181171
const load = async () => {
182172
const reg_paths = this._extension_context.workspaceState.get<string[]>(
183173
CONTEXT_SELECTED_PATHS_STATE_KEY
184174
)
185-
const reg_times = this._extension_context.workspaceState.get<
186-
Record<string, number>
187-
>(CONTEXT_SELECTED_TIMESTAMPS_STATE_KEY)
188175

189176
await this.gitignore_initialization
190177

191178
if (reg_paths && reg_paths.length > 0) {
192-
await this.set_selected_files(
193-
reg_paths,
194-
reg_times ? new Map(Object.entries(reg_times)) : undefined
195-
)
179+
await this.set_selected_files(reg_paths)
196180
}
197181
}
198182
load()
@@ -202,15 +186,10 @@ export class WorkspaceProvider
202186
return {
203187
selected_files: Array.from(this._checked_items.entries())
204188
.filter(([, state]) => state === vscode.TreeItemCheckboxState.Checked)
205-
.map(([path]) => path),
206-
selected_timestamps: Object.fromEntries(this._selected_timestamps)
189+
.map(([path]) => path)
207190
}
208191
}
209192

210-
get_selection_timestamp(path: string): number | undefined {
211-
return this._selected_timestamps.get(path)
212-
}
213-
214193
get_workspace_root_for_file(file_path: string): string | undefined {
215194
if (this._file_workspace_map.has(file_path)) {
216195
return this._file_workspace_map.get(file_path)
@@ -257,7 +236,6 @@ export class WorkspaceProvider
257236

258237
for (const file_path of files_to_uncheck) {
259238
this._checked_items.set(file_path, vscode.TreeItemCheckboxState.Unchecked)
260-
this._selected_timestamps.delete(file_path)
261239

262240
let dir_path = path.dirname(file_path)
263241
const workspace_root = this.get_workspace_root_for_file(file_path)
@@ -450,7 +428,6 @@ export class WorkspaceProvider
450428
if (!fs.existsSync(changed_file_path)) {
451429
this._file_workspace_map.delete(changed_file_path)
452430
this._checked_items.delete(changed_file_path)
453-
this._selected_timestamps.delete(changed_file_path)
454431
this._partially_selected_dirs.delete(changed_file_path)
455432

456433
let parent_dir = path.dirname(changed_file_path)
@@ -579,7 +556,6 @@ export class WorkspaceProvider
579556
} else {
580557
this._file_workspace_map.delete(file_path)
581558
this._checked_items.delete(file_path)
582-
this._selected_timestamps.delete(file_path)
583559
this._partially_selected_dirs.delete(file_path)
584560
}
585561

@@ -602,7 +578,6 @@ export class WorkspaceProvider
602578

603579
async clear_selected_files(): Promise<void> {
604580
this._checked_items.clear()
605-
this._selected_timestamps.clear()
606581
this._partially_selected_dirs.clear()
607582
this._token_calculator.clear_selected_counts()
608583

@@ -1043,13 +1018,6 @@ export class WorkspaceProvider
10431018
}
10441019

10451020
this._checked_items.set(key, state)
1046-
if (state === vscode.TreeItemCheckboxState.Checked) {
1047-
if (!this._selected_timestamps.has(key)) {
1048-
this._selected_timestamps.set(key, Math.floor(Date.now() / 1000))
1049-
}
1050-
} else {
1051-
this._selected_timestamps.delete(key)
1052-
}
10531021
this._token_calculator.invalidate_directory_selected_count(key)
10541022

10551023
if (item.isDirectory) {
@@ -1240,16 +1208,6 @@ export class WorkspaceProvider
12401208
}
12411209

12421210
this._checked_items.set(full_path, state)
1243-
if (state === vscode.TreeItemCheckboxState.Checked) {
1244-
if (!this._selected_timestamps.has(full_path)) {
1245-
this._selected_timestamps.set(
1246-
full_path,
1247-
Math.floor(Date.now() / 1000)
1248-
)
1249-
}
1250-
} else {
1251-
this._selected_timestamps.delete(full_path)
1252-
}
12531211

12541212
if (entry.isDirectory()) {
12551213
await this._update_directory_checkbox_state(full_path, state, false)
@@ -1293,14 +1251,9 @@ export class WorkspaceProvider
12931251
.map(([path]) => path)
12941252
}
12951253

1296-
async set_selected_files(
1297-
file_paths: string[],
1298-
timestamps?: Map<string, number>
1299-
): Promise<void> {
1254+
async set_selected_files(file_paths: string[]): Promise<void> {
13001255
await this.gitignore_initialization
1301-
const old_timestamps = new Map(this._selected_timestamps)
13021256
this._checked_items.clear()
1303-
this._selected_timestamps.clear()
13041257
this._partially_selected_dirs.clear()
13051258
this._token_calculator.clear_selected_counts()
13061259

@@ -1345,12 +1298,6 @@ export class WorkspaceProvider
13451298

13461299
for (const file_path of all_files_to_check) {
13471300
this._checked_items.set(file_path, vscode.TreeItemCheckboxState.Checked)
1348-
1349-
const timestamp =
1350-
timestamps?.get(file_path) ??
1351-
old_timestamps.get(file_path) ??
1352-
Math.floor(Date.now() / 1000)
1353-
this._selected_timestamps.set(file_path, timestamp)
13541301
}
13551302

13561303
for (const file_path of [...file_paths, ...all_files_to_check]) {

‎apps/editor/src/utils/files-collector.ts‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export namespace FilesCollector {
112112
recent_files: string[]
113113
} => {
114114
const recently_modified: Array<{ path: string; mtime: number }> = []
115-
const older_files: Array<{ path: string; timestamp: number }> = []
115+
const older_files: Array<{ path: string }> = []
116116
const now = Date.now()
117117
const ONE_AND_HALF_HOURS = 1.5 * 60 * 60 * 1000
118118

@@ -123,31 +123,19 @@ export namespace FilesCollector {
123123
if (stats.isDirectory()) continue
124124

125125
const mtime = stats.mtimeMs
126-
const selection_timestamp =
127-
params.workspace_provider.get_selection_timestamp(file_path) ?? now
128126

129127
if (now - mtime < ONE_AND_HALF_HOURS) {
130128
recently_modified.push({ path: file_path, mtime })
131129
} else {
132-
older_files.push({ path: file_path, timestamp: selection_timestamp })
130+
older_files.push({ path: file_path })
133131
}
134132
} catch (error) {
135133
console.error(`Error getting file stats for ${file_path}:`, error)
136134
}
137135
}
138136

139-
// Sort older files by selection timestamp (ascending), with natural sort as tiebreaker
140-
// Files selected within 20 seconds of each other are grouped and sorted naturally
141-
older_files.sort((a, b) => {
142-
const timestamp_bucket_a = Math.floor(a.timestamp / 20)
143-
const timestamp_bucket_b = Math.floor(b.timestamp / 20)
144-
const bucket_diff = timestamp_bucket_a - timestamp_bucket_b
145-
if (bucket_diff !== 0) {
146-
return bucket_diff
147-
}
148-
// If timestamps are within the same 20-second bucket, use natural sort on paths
149-
return natural_sort(a.path, b.path)
150-
})
137+
// Sort older files naturally by path
138+
older_files.sort((a, b) => natural_sort(a.path, b.path))
151139

152140
recently_modified.sort((a, b) => a.mtime - b.mtime)
153141

0 commit comments

Comments
 (0)