Skip to content

Commit 1e1f2e0

Browse files
committed
Add folder-specific intelligent search mode that searches all files in a folder
- 'intelligent search' when run on a specific directory, should consider all its files (not just selected ones) [Accuracy boost] - 'intelligent search' when run on a specific directory, should have different description: 'Send prompt with all files in this folder' - add missing translations [Fragment] └── apps └── editor ├── package.json └── src ├── commands │ └── search-files-commands │ ├── index.ts │ ├── search-files-commands.ts │ └── utils │ ├── get-target-folder-path.ts │ └── prompt-for-provided-results.ts ├── context │ └── providers │ └── workspace │ └── workspace-provider.ts ├── extension.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 │ ├── 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 │ ├── show-search-results-quick-pick.ts │ └── shrink-file │ ├── index.ts │ ├── languages │ │ ├── c-style.ts │ │ ├── css.ts │ │ ├── html.ts │ │ ├── jsx.ts │ │ ├── python.ts │ │ ├── ruby.ts │ │ └── sql.ts │ └── shrink-file.ts └── i18n └── translations └── features └── search-files.ts
1 parent 0212594 commit 1e1f2e0

3 files changed

Lines changed: 74 additions & 45 deletions

File tree

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

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,17 @@ export const search_files = async (params: {
6161
})
6262
}
6363

64+
const is_folder_search =
65+
!!params.folder_path &&
66+
!params.is_workspace_action &&
67+
!params.is_search_in_selected
68+
6469
while (true) {
6570
try {
6671
const mode_result = await prompt_for_search_mode(
6772
initial_search_mode,
68-
params.show_back_button
73+
params.show_back_button,
74+
is_folder_search
6975
)
7076

7177
if (mode_result === 'back') return 'back'
@@ -104,33 +110,35 @@ export const search_files = async (params: {
104110
let is_search_in_selected = params.is_search_in_selected
105111

106112
if (!is_search_in_selected && !params.is_sub_search) {
107-
const currently_selected =
108-
params.workspace_provider.get_selected_files()
109-
110-
if (currently_selected.length === 0) {
111-
vscode.window.showWarningMessage(
112-
t('command.search-files-command.warning.no-files-selected')
113-
)
114-
continue
115-
}
116-
117-
let files_to_search = currently_selected
118-
if (params.folder_path) {
119-
files_to_search = currently_selected.filter((f) => {
120-
const relative = path.relative(params.folder_path!, f)
121-
return !relative.startsWith('..') && !path.isAbsolute(relative)
122-
})
113+
if (!params.folder_path || params.is_workspace_action) {
114+
const currently_selected =
115+
params.workspace_provider.get_selected_files()
116+
117+
if (currently_selected.length === 0) {
118+
vscode.window.showWarningMessage(
119+
t('command.search-files-command.warning.no-files-selected')
120+
)
121+
continue
122+
}
123+
124+
let files_to_search = currently_selected
125+
if (params.folder_path) {
126+
files_to_search = currently_selected.filter((f) => {
127+
const relative = path.relative(params.folder_path!, f)
128+
return !relative.startsWith('..') && !path.isAbsolute(relative)
129+
})
130+
}
131+
132+
if (files_to_search.length === 0) {
133+
vscode.window.showInformationMessage(
134+
t('feature.search-files.info.no-files-selected-in-folder')
135+
)
136+
continue
137+
}
138+
139+
files = files_to_search
140+
is_search_in_selected = true
123141
}
124-
125-
if (files_to_search.length === 0) {
126-
vscode.window.showInformationMessage(
127-
t('feature.search-files.info.no-files-selected-in-folder')
128-
)
129-
continue
130-
}
131-
132-
files = files_to_search
133-
is_search_in_selected = true
134142
}
135143

136144
flow_result = await perform_intelligent_search_mode({

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { t } from '@/i18n'
33

44
export const prompt_for_search_mode = async (
55
last_mode: 'phrase' | 'keywords' | 'intelligent',
6-
show_back_button?: boolean
6+
show_back_button?: boolean,
7+
is_folder_search?: boolean
78
): Promise<'phrase' | 'keywords' | 'intelligent' | undefined | 'back'> => {
89
const items: (vscode.QuickPickItem & {
910
mode: 'phrase' | 'keywords' | 'intelligent'
@@ -20,7 +21,9 @@ export const prompt_for_search_mode = async (
2021
},
2122
{
2223
label: t('feature.search-files.mode.intelligent'),
23-
description: t('feature.search-files.mode.intelligent-description'),
24+
description: is_folder_search
25+
? t('feature.search-files.mode.intelligent-description-folder')
26+
: t('feature.search-files.mode.intelligent-description'),
2427
mode: 'intelligent'
2528
}
2629
]

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

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -360,22 +360,40 @@ export const translations = {
360360
bg: 'Интелигентен'
361361
},
362362
'feature.search-files.mode.intelligent-description': {
363-
en: 'Send prompt with the selected files',
364-
pl: 'Wyślij prompt z wybranymi plikami',
365-
'zh-cn': '发送包含所选文件的提示词',
366-
ja: '選択したファイルと共にプロンプトを送信',
367-
'zh-tw': '發送包含所選檔案的提示詞',
368-
de: 'Prompt mit den ausgewählten Dateien senden',
369-
es: 'Enviar prompt con los archivos seleccionados',
370-
fr: 'Envoyer le prompt avec les fichiers sélectionnés',
371-
'pt-br': 'Enviar prompt com os arquivos selecionados',
372-
ru: 'Отправить промпт с выбранными файлами',
373-
ko: '선택한 파일과 함께 프롬프트 전송',
374-
it: 'Invia prompt con i file selezionati',
375-
tr: 'Seçili dosyalarla istem gönder',
376-
cs: 'Odeslat prompt s vybranými soubory',
377-
hu: 'Prompt küldése a kiválasztott fájlokkal',
378-
bg: 'Изпращане на промпт с избраните файлове'
363+
en: 'Prompt with the selected files',
364+
pl: 'Prompt z wybranymi plikami',
365+
'zh-cn': '使用所选文件进行提示',
366+
ja: '選択したファイルでプロンプトを実行',
367+
'zh-tw': '使用所選檔案進行提示',
368+
de: 'Mit den ausgewählten Dateien abfragen',
369+
es: 'Preguntar con los archivos seleccionados',
370+
fr: 'Interroger avec les fichiers sélectionnés',
371+
'pt-br': 'Perguntar com os arquivos selecionados',
372+
ru: 'Запрос с выбранными файлами',
373+
ko: '선택한 파일로 프롬프트',
374+
it: 'Richiedi con i file selezionati',
375+
tr: 'Seçili dosyalarla sorgula',
376+
cs: 'Dotaz s vybranými soubory',
377+
hu: 'Kérdezzen a kiválasztott fájlokkal',
378+
bg: 'Запитване с избраните файлове'
379+
},
380+
'feature.search-files.mode.intelligent-description-folder': {
381+
en: 'Prompt with all files in this folder',
382+
pl: 'Prompt ze wszystkimi plikami w tym folderze',
383+
'zh-cn': '使用此文件夹中的所有文件进行提示',
384+
ja: 'このフォルダ内のすべてのファイルでプロンプトを実行',
385+
'zh-tw': '使用此資料夾中的所有檔案進行提示',
386+
de: 'Mit allen Dateien in diesem Ordner abfragen',
387+
es: 'Preguntar con todos los archivos en esta carpeta',
388+
fr: 'Interroger avec tous les fichiers de ce dossier',
389+
'pt-br': 'Perguntar com todos os arquivos nesta pasta',
390+
ru: 'Запрос со всеми файлами в этой папке',
391+
ko: '이 폴더의 모든 파일로 프롬프트',
392+
it: 'Richiedi con tutti i file in questa cartella',
393+
tr: 'Bu klasördeki tüm dosyalarla sorgula',
394+
cs: 'Dotaz se všemi soubory v této složce',
395+
hu: 'Kérdezzen a mappában lévő összes fájllal',
396+
bg: 'Запитване с всички файлове в тази папка'
379397
},
380398
'feature.search-files.prompt.intelligent': {
381399
en: 'Enter natural language search query.',

0 commit comments

Comments
 (0)