Skip to content

Commit 3444beb

Browse files
committed
Refactor search results prompts to support custom grouping labels and unmatched file restoration
- are unmatched files listed when applying 'intelligent search results' from clipboard? they should - the second separator should say in ths case 'unmatched selected fiels · stitcher' - the second, 'unmatched..' separator should not include the workspace root folder name as matched/unmatched are integral and we're already showing root folder name in a separator above - top separator should say 'results in stitcher' └── apps └── editor └── src ├── commands │ ├── apply-response-command │ │ ├── apply-response-command.ts │ │ └── response-processor.ts │ └── search-files-commands │ ├── index.ts │ ├── search-files-commands.ts │ └── utils │ ├── get-target-folder-path.ts │ └── prompt-for-provided-results.ts ├── features │ └── search-files │ ├── index.ts │ ├── search-files.ts │ ├── search-modes │ │ ├── perform-intelligent-search-mode.ts │ │ ├── perform-keywords-search-mode.ts │ │ └── perform-phrase-search-mode.ts │ └── utils │ ├── analyze-files.ts │ ├── check-matches-condition.ts │ ├── create-search-regex.ts │ ├── group-quick-pick-items.ts │ ├── handle-parent-folder-result.ts │ ├── map-files-to-quick-pick-items.ts │ ├── prompt-for-config.ts │ ├── prompt-for-intelligent-search-results.ts │ ├── prompt-for-keywords-match-mode.ts │ ├── prompt-for-keywords-target.ts │ ├── prompt-for-search-mode.ts │ ├── prompt-for-search-results.ts │ ├── prompt-for-search-term.ts │ ├── prompt-for-shrink-mode.ts │ ├── search-files-by-intelligent.ts │ ├── search-files-by-keywords.ts │ └── search-files-by-phrase.ts ├── i18n │ └── translations │ └── features │ └── search-files.ts └── utils └── natural-sort.ts
1 parent da59373 commit 3444beb

6 files changed

Lines changed: 125 additions & 43 deletions

File tree

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

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,47 @@ export const search_files_commands = (
114114
}
115115
) => {
116116
if (options?.provided_files) {
117+
let resolved_all_files: string[] = []
118+
119+
if (options.is_search_in_selected) {
120+
const currently_checked = workspace_provider.get_checked_files()
121+
if (options.folder_path) {
122+
resolved_all_files = currently_checked.filter((f) => {
123+
const relative = path.relative(options.folder_path!, f)
124+
return !relative.startsWith('..') && !path.isAbsolute(relative)
125+
})
126+
} else {
127+
resolved_all_files = currently_checked
128+
}
129+
} else {
130+
if (options.folder_path) {
131+
resolved_all_files = await workspace_provider.find_all_files(
132+
options.folder_path
133+
)
134+
} else {
135+
const roots = workspace_provider.get_workspace_roots()
136+
for (const root of roots) {
137+
const result = await workspace_provider.find_all_files(root)
138+
resolved_all_files.push(...result)
139+
}
140+
}
141+
}
142+
117143
let decision:
118144
| { selected_paths: string[]; matched_paths: string[]; title?: string }
119145
| undefined = undefined
120146

121147
let restored_selected_paths: string[] | undefined = undefined
148+
let restored_unmatched_paths: string[] | undefined = undefined
122149

123150
while (true) {
124151
const result = await prompt_for_provided_results({
125152
files: options.provided_files,
126153
workspace_provider,
127-
restored_selected_paths
154+
restored_selected_paths,
155+
restored_unmatched_paths,
156+
is_search_in_selected: options.is_search_in_selected,
157+
searched_files: resolved_all_files
128158
})
129159

130160
if (!result) return
@@ -141,6 +171,7 @@ export const search_files_commands = (
141171

142172
if (sub_search_result === 'back') {
143173
restored_selected_paths = result.selected_paths
174+
restored_unmatched_paths = result.unmatched_paths
144175
continue
145176
}
146177

@@ -154,32 +185,6 @@ export const search_files_commands = (
154185
break
155186
}
156187

157-
let resolved_all_files: string[] = []
158-
159-
if (options.is_search_in_selected) {
160-
const currently_checked = workspace_provider.get_checked_files()
161-
if (options.folder_path) {
162-
resolved_all_files = currently_checked.filter((f) => {
163-
const relative = path.relative(options.folder_path!, f)
164-
return !relative.startsWith('..') && !path.isAbsolute(relative)
165-
})
166-
} else {
167-
resolved_all_files = currently_checked
168-
}
169-
} else {
170-
if (options.folder_path) {
171-
resolved_all_files = await workspace_provider.find_all_files(
172-
options.folder_path
173-
)
174-
} else {
175-
const roots = workspace_provider.get_workspace_roots()
176-
for (const root of roots) {
177-
const result = await workspace_provider.find_all_files(root)
178-
resolved_all_files.push(...result)
179-
}
180-
}
181-
}
182-
183188
await process_search_result({
184189
result: decision,
185190
resolved_all_files,

‎apps/editor/src/commands/search-files-commands/utils/prompt-for-provided-results.ts‎

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ export const prompt_for_provided_results = async (params: {
1111
files: { path: string; checked: boolean }[]
1212
workspace_provider: WorkspaceProvider
1313
restored_selected_paths?: string[]
14+
restored_unmatched_paths?: string[]
15+
is_search_in_selected?: boolean
16+
searched_files?: string[]
1417
}): Promise<
1518
| { selected_paths: string[]; matched_paths: string[]; title: string }
1619
| {
1720
action: 'search-in-results'
1821
matched_paths: string[]
1922
selected_paths: string[]
23+
unmatched_paths: string[]
2024
}
2125
| undefined
2226
> => {
@@ -37,9 +41,20 @@ export const prompt_for_provided_results = async (params: {
3741
tooltip: t('common.search-in-selected-results')
3842
}
3943

44+
const currently_checked = params.workspace_provider.get_checked_files()
4045
const is_multi_root =
4146
params.workspace_provider.get_workspace_roots().length > 1
4247

48+
const matched_paths = params.files.map((f) => f.path)
49+
50+
const unmatched_checked_files =
51+
params.restored_unmatched_paths ??
52+
(params.is_search_in_selected
53+
? (params.searched_files || currently_checked).filter(
54+
(f) => currently_checked.includes(f) && !matched_paths.includes(f)
55+
)
56+
: [])
57+
4358
const mapped_items = await map_files_to_quick_pick_items({
4459
files: params.files,
4560
is_multi_root,
@@ -57,6 +72,25 @@ export const prompt_for_provided_results = async (params: {
5772
checked?: boolean
5873
})[]
5974

75+
if (unmatched_checked_files.length > 0) {
76+
const mapped_unmatched_items = await map_files_to_quick_pick_items({
77+
files: unmatched_checked_files.map((path) => ({ path })),
78+
is_multi_root,
79+
workspace_provider: params.workspace_provider,
80+
open_file_button,
81+
add_parent_folder_button
82+
})
83+
84+
const unmatched_quick_pick_items = group_quick_pick_items({
85+
mapped_items: mapped_unmatched_items,
86+
is_multi_root: false,
87+
workspace_provider: params.workspace_provider,
88+
label_prefix: t('feature.search-files.results.unmatched')
89+
}) as (vscode.QuickPickItem & { file_path?: string })[]
90+
91+
quick_pick_items.push(...unmatched_quick_pick_items)
92+
}
93+
6094
const quick_pick = vscode.window.createQuickPick<
6195
vscode.QuickPickItem & { file_path?: string; checked?: boolean }
6296
>()
@@ -66,7 +100,10 @@ export const prompt_for_provided_results = async (params: {
66100
if (params.restored_selected_paths) {
67101
return params.restored_selected_paths.includes(item.file_path)
68102
}
69-
return item.checked
103+
if (unmatched_checked_files.includes(item.file_path)) {
104+
return false
105+
}
106+
return item.checked !== undefined ? item.checked : false
70107
})
71108
quick_pick.canSelectMany = true
72109
quick_pick.matchOnDescription = true
@@ -103,6 +140,7 @@ export const prompt_for_provided_results = async (params: {
103140
action: 'search-in-results'
104141
matched_paths: string[]
105142
selected_paths: string[]
143+
unmatched_paths: string[]
106144
}
107145
| undefined
108146
>((resolve) => {
@@ -125,7 +163,8 @@ export const prompt_for_provided_results = async (params: {
125163
resolve({
126164
action: 'search-in-results',
127165
matched_paths: selected,
128-
selected_paths: selected
166+
selected_paths: selected,
167+
unmatched_paths: unmatched_checked_files
129168
})
130169
quick_pick.hide()
131170
} else if (button === close_button) {
@@ -140,7 +179,10 @@ export const prompt_for_provided_results = async (params: {
140179
selected_paths: quick_pick.selectedItems
141180
.map((item) => item.file_path)
142181
.filter((p): p is string => p !== undefined),
143-
matched_paths: params.files.map((f) => f.path),
182+
matched_paths: [
183+
...params.files.map((f) => f.path),
184+
...unmatched_checked_files
185+
],
144186
title: base_title
145187
})
146188
quick_pick.hide()

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import * as vscode from 'vscode'
22
import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provider'
3+
import { t } from '@/i18n'
34

45
export const group_quick_pick_items = <
56
T extends vscode.QuickPickItem & { workspace_name?: string }
67
>(params: {
78
mapped_items: T[]
89
is_multi_root: boolean
910
workspace_provider: WorkspaceProvider
11+
label_prefix?: string
1012
}): T[] => {
1113
const quick_pick_items: T[] = []
1214

@@ -28,13 +30,34 @@ export const group_quick_pick_items = <
2830
for (const ws of unique_ordered_workspaces) {
2931
if (grouped.has(ws)) {
3032
quick_pick_items.push({
31-
label: ws,
33+
label: params.label_prefix
34+
? `${params.label_prefix} · ${ws}`
35+
: t('feature.search-files.results.in-workspace', { workspace: ws }),
3236
kind: vscode.QuickPickItemKind.Separator
3337
} as T)
3438
quick_pick_items.push(...grouped.get(ws)!)
3539
}
3640
}
3741
} else {
42+
if (params.mapped_items.length > 0) {
43+
if (params.label_prefix) {
44+
quick_pick_items.push({
45+
label: params.label_prefix,
46+
kind: vscode.QuickPickItemKind.Separator
47+
} as T)
48+
} else {
49+
const root = params.workspace_provider.get_workspace_roots()[0]
50+
const ws_name = root
51+
? params.workspace_provider.get_workspace_name(root)
52+
: ''
53+
quick_pick_items.push({
54+
label: t('feature.search-files.results.in-workspace', {
55+
workspace: ws_name
56+
}),
57+
kind: vscode.QuickPickItemKind.Separator
58+
} as T)
59+
}
60+
}
3861
quick_pick_items.push(...params.mapped_items)
3962
}
4063

‎apps/editor/src/features/search-files/utils/prompt-for-intelligent-search-results.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,11 @@ export const prompt_for_intelligent_search_results = async (params: {
107107

108108
const unmatched_quick_pick_items = group_quick_pick_items({
109109
mapped_items: mapped_unmatched_items,
110-
is_multi_root,
111-
workspace_provider: params.workspace_provider
110+
is_multi_root: false,
111+
workspace_provider: params.workspace_provider,
112+
label_prefix: t('feature.search-files.results.unmatched')
112113
}) as (vscode.QuickPickItem & { file_path?: string })[]
113114

114-
quick_pick_items.push({
115-
label: t('feature.search-files.results.unmatched'),
116-
kind: vscode.QuickPickItemKind.Separator
117-
})
118115
quick_pick_items.push(...unmatched_quick_pick_items)
119116
}
120117

‎apps/editor/src/features/search-files/utils/prompt-for-search-results.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,11 @@ export const prompt_for_search_results = async (params: {
8484

8585
const unmatched_quick_pick_items = group_quick_pick_items({
8686
mapped_items: mapped_unmatched_items,
87-
is_multi_root,
88-
workspace_provider: params.workspace_provider
87+
is_multi_root: false,
88+
workspace_provider: params.workspace_provider,
89+
label_prefix: t('feature.search-files.results.unmatched')
8990
}) as (vscode.QuickPickItem & { file_path?: string })[]
9091

91-
quick_pick_items.push({
92-
label: t('feature.search-files.results.unmatched'),
93-
kind: vscode.QuickPickItemKind.Separator
94-
})
9592
quick_pick_items.push(...unmatched_quick_pick_items)
9693
}
9794

‎apps/editor/src/i18n/translations/features/search-files.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,24 @@ export const translations = {
953953
hu: 'Keresés tartalmában és fájlnevekben egyaránt',
954954
bg: 'Търсене както в съдържанието, така и в имената на файловете'
955955
},
956+
'feature.search-files.results.in-workspace': {
957+
en: 'results in {workspace}',
958+
pl: 'wyniki w {workspace}',
959+
'zh-cn': '{workspace} 中的结果',
960+
ja: '{workspace} の結果',
961+
'zh-tw': '{workspace} 中的結果',
962+
de: 'Ergebnisse in {workspace}',
963+
es: 'resultados en {workspace}',
964+
fr: 'résultats dans {workspace}',
965+
'pt-br': 'resultados em {workspace}',
966+
ru: 'результаты в {workspace}',
967+
ko: '{workspace}의 결과',
968+
it: 'risultati in {workspace}',
969+
tr: "{workspace}'deki sonuçlar",
970+
cs: 'výsledky v {workspace}',
971+
hu: 'eredmények itt: {workspace}',
972+
bg: 'резултати в {workspace}'
973+
},
956974
'feature.search-files.results.unmatched': {
957975
en: 'unmatched selected files',
958976
pl: 'Niedopasowane wybrane pliki',

0 commit comments

Comments
 (0)