Skip to content

Commit 5d67627

Browse files
committed
Merge branch 'dev' of github.com:robertpiosik/CodeWebChat into dev
2 parents ef4ec29 + 4dd6c2e commit 5d67627

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

‎apps/editor/src/features/search-files/utils/map-files-to-quick-pick-items.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode'
22
import * as path from 'path'
33
import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provider'
44
import { display_token_count } from '@shared/utils/display-token-count'
5+
import { natural_sort } from '@/utils/natural-sort'
56

67
export const map_files_to_quick_pick_items = async <
78
T extends { path: string }
@@ -12,8 +13,28 @@ export const map_files_to_quick_pick_items = async <
1213
open_file_button: vscode.QuickInputButton
1314
add_parent_folder_button: vscode.QuickInputButton
1415
}) => {
16+
const get_sort_path = (file_path: string) => {
17+
const workspace_root =
18+
params.workspace_provider.get_workspace_root_for_file(file_path)
19+
const relative_path = workspace_root
20+
? path.relative(workspace_root, file_path)
21+
: file_path
22+
23+
if (workspace_root && params.is_multi_root) {
24+
const workspace_name =
25+
params.workspace_provider.get_workspace_name(workspace_root)
26+
return `${workspace_name}/${relative_path}`
27+
}
28+
29+
return relative_path
30+
}
31+
32+
const sorted_files = [...params.files].sort((a, b) =>
33+
natural_sort(get_sort_path(a.path), get_sort_path(b.path))
34+
)
35+
1536
return await Promise.all(
16-
params.files.map(async (file_obj) => {
37+
sorted_files.map(async (file_obj) => {
1738
const file_path = file_obj.path
1839
const workspace_root =
1940
params.workspace_provider.get_workspace_root_for_file(file_path)

0 commit comments

Comments
 (0)