Skip to content

Commit d5b51ad

Browse files
committed
Refactor the @ quick pick logic to search against filenames, display a warning when no results are found, and centralize the "Nothing selected in context" warning message in the dictionary
1 parent b04cfe7 commit d5b51ad

2 files changed

Lines changed: 29 additions & 11 deletions

File tree

‎packages/shared/src/constants/dictionary.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const dictionary = {
6262
CONTEXTS_FILE_NOT_VALID_ARRAY:
6363
'Contexts file is not a valid array. Starting with empty contexts list.',
6464
NO_FILES_OR_WEBSITES_SELECTED: 'No files or websites selected or open.',
65+
NOTHING_SELECTED_IN_CONTEXT: 'Nothing is selected in context.',
6566
NO_OPEN_EDITORS_SELECTED: 'No open editors selected.',
6667
NO_EDITOR_OPEN: 'No editor is open.',
6768
CANNOT_COPY_PROMPT_IN_CODE_COMPLETION_WITH_SELECTION:
@@ -108,6 +109,8 @@ export const dictionary = {
108109
`Are you sure you want to delete the model provider "${provider_name}"?`,
109110
NO_MODELS_FOUND_MANUAL_ENTRY: (provider_name: string) =>
110111
`No models found for ${provider_name}. You can enter model name manually.`,
112+
NO_RESULTS_FOR_SEARCH_SHOWING_ALL: (search_value: string) =>
113+
`No results for "${search_value}" in the selected context. Showing all items.`,
111114
NO_MODEL_PROVIDERS_CONFIGURED:
112115
'No model providers configured. Please add a model provider first on the "Model Providers" page.'
113116
},

‎packages/vscode/src/views/panel/backend/message-handlers/handle-at-sign-quick-pick.ts‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@ import * as vscode from 'vscode'
55
import * as path from 'path'
66
import { WorkspaceProvider } from '@/context/providers/workspace-provider'
77
import { natural_sort } from '@/utils/natural-sort'
8+
import { dictionary } from '@shared/constants/dictionary'
89

910
const at_sign_quick_pick = async (params: {
1011
workspace_provider: WorkspaceProvider
1112
search_value?: string
1213
}): Promise<string | undefined> => {
1314
const checked_paths = params.workspace_provider.get_all_checked_paths()
1415
if (checked_paths.length == 0) {
15-
vscode.window.showWarningMessage('Nothing is selected in context.')
16+
vscode.window.showWarningMessage(
17+
dictionary.warning_message.NOTHING_SELECTED_IN_CONTEXT
18+
)
1619
return
1720
}
1821

1922
const workspace_roots = params.workspace_provider.getWorkspaceRoots()
2023

21-
const quick_pick_items = checked_paths
24+
const all_quick_pick_items = checked_paths
2225
.filter((p) => {
2326
try {
2427
return fs.existsSync(p) && fs.statSync(p).isFile()
@@ -47,19 +50,31 @@ const at_sign_quick_pick = async (params: {
4750
fullPath: normalized_path
4851
}
4952
})
50-
.filter((item) => {
51-
if (params.search_value) {
52-
const search_lower = params.search_value.toLowerCase()
53-
const full_path_lower = item.fullPath.toLowerCase()
54-
return full_path_lower.includes(search_lower)
55-
}
56-
return true
53+
54+
let quick_pick_items_to_show = all_quick_pick_items
55+
56+
if (params.search_value) {
57+
const filtered_items = all_quick_pick_items.filter((item) => {
58+
const search_lower = params.search_value!.toLowerCase()
59+
const filename_lower = item.label.toLowerCase()
60+
return filename_lower.includes(search_lower)
5761
})
5862

59-
quick_pick_items.sort((a, b) => natural_sort(a.fullPath, b.fullPath))
63+
if (filtered_items.length > 0) {
64+
quick_pick_items_to_show = filtered_items
65+
} else {
66+
vscode.window.showWarningMessage(
67+
dictionary.warning_message.NO_RESULTS_FOR_SEARCH_SHOWING_ALL(
68+
params.search_value
69+
)
70+
)
71+
}
72+
}
73+
74+
quick_pick_items_to_show.sort((a, b) => natural_sort(a.fullPath, b.fullPath))
6075

6176
const selected_path_item = await vscode.window.showQuickPick(
62-
quick_pick_items,
77+
quick_pick_items_to_show,
6378
{
6479
placeHolder: 'Select a path to place in the input field',
6580
matchOnDescription: true

0 commit comments

Comments
 (0)