Skip to content

Commit d1823d3

Browse files
committed
Refactor file search to use lazy loading and add keyword search target options
- in large codebases the command shows the intial quick pick with a significant dealy - while searching phrase, keywords, should show progress notification - in recent changes we introduced progress notification. It should not show file paths. [Changes] - rename 'searching files' to 'searching...' (with translations) - add missing translations [Fragment] - add missing translations[Fragment]
1 parent 2d50974 commit d1823d3

12 files changed

Lines changed: 482 additions & 213 deletions

File tree

‎apps/editor/src/commands/search-files-commands.ts‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,35 @@ export const search_files_commands = (
3232
const search_handler = async (item?: any) => {
3333
const folder_path = await get_target_folder_path(item)
3434

35-
let all_files: string[] = []
36-
37-
if (folder_path) {
38-
all_files = await workspace_provider.find_all_files(folder_path)
39-
} else {
40-
const roots = workspace_provider.get_workspace_roots()
41-
for (const root of roots) {
42-
const files = await workspace_provider.find_all_files(root)
43-
all_files.push(...files)
35+
let all_files: string[] | undefined
36+
37+
const get_files_lazy = async () => {
38+
if (all_files) return all_files
39+
const files: string[] = []
40+
if (folder_path) {
41+
const result = await workspace_provider.find_all_files(folder_path)
42+
files.push(...result)
43+
} else {
44+
const roots = workspace_provider.get_workspace_roots()
45+
for (const root of roots) {
46+
const result = await workspace_provider.find_all_files(root)
47+
files.push(...result)
48+
}
4449
}
50+
all_files = files
51+
return all_files
4552
}
4653

4754
const result = await search_files({
48-
files: all_files,
55+
get_files: get_files_lazy,
4956
workspace_provider,
5057
extension_context
5158
})
5259

5360
if (!result || result == 'back') return
5461

62+
const resolved_all_files = await get_files_lazy()
63+
5564
const { selected_paths, matched_paths } = result
5665

5766
const unchecked_paths = matched_paths.filter(
@@ -60,7 +69,7 @@ export const search_files_commands = (
6069

6170
const currently_checked = workspace_provider.get_checked_files()
6271
const currently_checked_in_folder = currently_checked.filter((f) =>
63-
all_files.includes(f)
72+
resolved_all_files.includes(f)
6473
)
6574

6675
let paths_to_apply: string[] = []
@@ -163,7 +172,7 @@ export const search_files_commands = (
163172
} else {
164173
paths_to_apply = [
165174
...new Set([
166-
...currently_checked.filter((p) => !all_files.includes(p)),
175+
...currently_checked.filter((p) => !resolved_all_files.includes(p)),
167176
...selected_paths
168177
])
169178
]

‎apps/editor/src/commands/select-imported-files-command/select-imported-files-command.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ export const select_imported_files_command = (
359359
}
360360

361361
const search_result = await search_files({
362-
files: paths_for_search,
362+
get_files: async () => paths_for_search,
363363
workspace_provider,
364364
extension_context,
365365
show_back_button: true

‎apps/editor/src/commands/select-referencing-files-command.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ export const select_referencing_files_command = (
374374

375375
if (selected_items === 'search') {
376376
const search_result = await search_files({
377-
files: matched_files.map((m) => m.file_path),
377+
get_files: async () => matched_files.map((m) => m.file_path),
378378
workspace_provider,
379379
extension_context,
380380
show_back_button: true

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export const LAST_SEARCH_FILES_KEYWORDS_QUERY_STATE_KEY =
8787
'last-search-files-keywords-query'
8888
export const LAST_SEARCH_FILES_KEYWORDS_MATCH_MODE_STATE_KEY =
8989
'last-search-files-keywords-match-mode'
90+
export const LAST_SEARCH_FILES_KEYWORDS_TARGET_STATE_KEY =
91+
'last-search-files-keywords-target'
9092
export const LAST_SEARCH_FILES_FILENAME_QUERY_STATE_KEY =
9193
'last-search-files-filename-query'
9294
export const LAST_SEARCH_FILES_FILENAME_MATCH_MODE_STATE_KEY =

0 commit comments

Comments
 (0)