Skip to content

Commit e5be8ca

Browse files
committed
Enable file reference selection even when no context files are selected and improve quick pick navigation
1 parent f90f8e0 commit e5be8ca

4 files changed

Lines changed: 331 additions & 64 deletions

File tree

packages/ui/src/components/editor/panel/PromptField/PromptField.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
372372
}
373373
}}
374374
onClick={() => {
375-
if (!has_no_context) {
376-
props.on_at_sign_click()
377-
}
375+
props.on_at_sign_click()
378376
}}
379377
onMouseLeave={() => set_show_at_sign_tooltip(false)}
380378
className={cn(styles['footer__left__button'])}

packages/vscode/src/commands/add-file-to-context-command.ts

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,34 @@ export const add_file_to_context_command = (
2222
}
2323

2424
const quick_pick = vscode.window.createQuickPick<FileQuickPickItem>()
25+
quick_pick.title = 'Workspace Files'
2526
quick_pick.placeholder = 'Select a file to add to context'
2627
quick_pick.matchOnDescription = true
28+
quick_pick.buttons = [
29+
{
30+
iconPath: new vscode.ThemeIcon('close'),
31+
tooltip: 'Close'
32+
}
33+
]
2734
quick_pick.busy = true
2835
quick_pick.show()
2936

37+
quick_pick.onDidTriggerButton((button) => {
38+
if (button.tooltip == 'Close') {
39+
quick_pick.hide()
40+
}
41+
})
42+
43+
let is_showing_folder_quick_pick = false
44+
let file_items_cache: FileQuickPickItem[] = []
45+
46+
let parent_folder_source_full_path: string | undefined
47+
3048
quick_pick.onDidTriggerItemButton(async (e) => {
3149
const item = e.item
3250
if (e.button.tooltip == 'Add Parent Folder to Context') {
51+
parent_folder_source_full_path = item.full_path
52+
3353
const workspace_root = workspace_provider.get_workspace_root_for_file(
3454
item.full_path
3555
)
@@ -60,15 +80,26 @@ export const add_file_to_context_command = (
6080
label: string
6181
full_path: string
6282
}>()
83+
folder_quick_pick.title = 'Parent Folders'
6384
folder_quick_pick.placeholder = 'Select a folder to add to context'
6485
folder_quick_pick.items = folders.map((f) => ({
6586
label: f.label,
6687
full_path: f.full_path
6788
}))
89+
folder_quick_pick.buttons = [vscode.QuickInputButtons.Back]
90+
91+
let folder_accepted = false
92+
93+
folder_quick_pick.onDidTriggerButton((button) => {
94+
if (button === vscode.QuickInputButtons.Back) {
95+
folder_quick_pick.hide()
96+
}
97+
})
6898

6999
folder_quick_pick.onDidAccept(async () => {
70100
const selected = folder_quick_pick.selectedItems[0]
71101
if (selected) {
102+
folder_accepted = true
72103
const file_item = new FileItem(
73104
path.basename(selected.full_path),
74105
vscode.Uri.file(selected.full_path),
@@ -95,8 +126,30 @@ export const add_file_to_context_command = (
95126

96127
folder_quick_pick.onDidHide(() => {
97128
folder_quick_pick.dispose()
129+
is_showing_folder_quick_pick = false
130+
131+
if (!folder_accepted) {
132+
if (file_items_cache.length > 0) {
133+
quick_pick.items = file_items_cache
134+
}
135+
quick_pick.show()
136+
137+
const source_item = parent_folder_source_full_path
138+
? file_items_cache.find(
139+
(i) => i.full_path === parent_folder_source_full_path
140+
)
141+
: undefined
142+
143+
if (source_item) {
144+
setTimeout(() => {
145+
quick_pick.activeItems = [source_item]
146+
}, 0)
147+
}
148+
}
98149
})
99150

151+
is_showing_folder_quick_pick = true
152+
quick_pick.hide()
100153
folder_quick_pick.show()
101154
}
102155
})
@@ -118,7 +171,9 @@ export const add_file_to_context_command = (
118171

119172
const filename = path.basename(relative_path)
120173
let directory = path.dirname(relative_path)
121-
if (directory === '.') {
174+
const has_parent_folder = directory != '.'
175+
176+
if (directory == '.') {
122177
directory = ''
123178
}
124179

@@ -134,12 +189,14 @@ export const add_file_to_context_command = (
134189
label: filename,
135190
description: directory,
136191
full_path: file_path,
137-
buttons: [
138-
{
139-
iconPath: new vscode.ThemeIcon('folder'),
140-
tooltip: 'Add Parent Folder to Context'
141-
}
142-
]
192+
buttons: has_parent_folder
193+
? [
194+
{
195+
iconPath: new vscode.ThemeIcon('folder'),
196+
tooltip: 'Add Parent Folder to Context'
197+
}
198+
]
199+
: []
143200
}
144201
})
145202

@@ -149,6 +206,7 @@ export const add_file_to_context_command = (
149206
return natural_sort(a.description || '', b.description || '')
150207
})
151208

209+
file_items_cache = items
152210
quick_pick.items = items
153211
quick_pick.busy = false
154212

@@ -167,6 +225,9 @@ export const add_file_to_context_command = (
167225
})
168226

169227
quick_pick.onDidHide(() => {
228+
if (is_showing_folder_quick_pick) {
229+
return
230+
}
170231
quick_pick.dispose()
171232
})
172233
} catch (error) {

packages/vscode/src/commands/remove-file-from-context-command.ts

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,33 @@ export const remove_file_from_context_command = (
2424
}
2525

2626
const quick_pick = vscode.window.createQuickPick<FileQuickPickItem>()
27+
quick_pick.title = 'Context Files'
2728
quick_pick.placeholder = 'Select a file to remove from context'
2829
quick_pick.matchOnDescription = true
30+
quick_pick.buttons = [
31+
{
32+
iconPath: new vscode.ThemeIcon('close'),
33+
tooltip: 'Close'
34+
}
35+
]
2936
quick_pick.show()
3037

38+
quick_pick.onDidTriggerButton((button) => {
39+
if (button.tooltip == 'Close') {
40+
quick_pick.hide()
41+
}
42+
})
43+
44+
let is_showing_folder_quick_pick = false
45+
let file_items_cache: FileQuickPickItem[] = []
46+
47+
let parent_folder_source_full_path: string | undefined
48+
3149
quick_pick.onDidTriggerItemButton(async (e) => {
3250
const item = e.item
3351
if (e.button.tooltip == 'Remove Parent Folder from Context') {
52+
parent_folder_source_full_path = item.full_path
53+
3454
const workspace_root = workspace_provider.get_workspace_root_for_file(
3555
item.full_path
3656
)
@@ -61,16 +81,27 @@ export const remove_file_from_context_command = (
6181
label: string
6282
full_path: string
6383
}>()
84+
folder_quick_pick.title = 'Parent Folders'
6485
folder_quick_pick.placeholder =
6586
'Select a folder to remove from context'
6687
folder_quick_pick.items = folders.map((f) => ({
6788
label: f.label,
6889
full_path: f.full_path
6990
}))
91+
folder_quick_pick.buttons = [vscode.QuickInputButtons.Back]
92+
93+
let folder_accepted = false
94+
95+
folder_quick_pick.onDidTriggerButton((button) => {
96+
if (button === vscode.QuickInputButtons.Back) {
97+
folder_quick_pick.hide()
98+
}
99+
})
70100

71101
folder_quick_pick.onDidAccept(async () => {
72102
const selected = folder_quick_pick.selectedItems[0]
73103
if (selected) {
104+
folder_accepted = true
74105
const file_item = new FileItem(
75106
path.basename(selected.full_path),
76107
vscode.Uri.file(selected.full_path),
@@ -97,8 +128,30 @@ export const remove_file_from_context_command = (
97128

98129
folder_quick_pick.onDidHide(() => {
99130
folder_quick_pick.dispose()
131+
is_showing_folder_quick_pick = false
132+
133+
if (!folder_accepted) {
134+
if (file_items_cache.length > 0) {
135+
quick_pick.items = file_items_cache
136+
}
137+
quick_pick.show()
138+
139+
const source_item = parent_folder_source_full_path
140+
? file_items_cache.find(
141+
(i) => i.full_path === parent_folder_source_full_path
142+
)
143+
: undefined
144+
145+
if (source_item) {
146+
setTimeout(() => {
147+
quick_pick.activeItems = [source_item]
148+
}, 0)
149+
}
150+
}
100151
})
101152

153+
is_showing_folder_quick_pick = true
154+
quick_pick.hide()
102155
folder_quick_pick.show()
103156
}
104157
})
@@ -115,6 +168,8 @@ export const remove_file_from_context_command = (
115168

116169
const filename = path.basename(relative_path)
117170
let directory = path.dirname(relative_path)
171+
const has_parent_folder = directory != '.'
172+
118173
if (directory == '.') {
119174
directory = ''
120175
}
@@ -131,12 +186,14 @@ export const remove_file_from_context_command = (
131186
label: filename,
132187
description: directory,
133188
full_path: file_path,
134-
buttons: [
135-
{
136-
iconPath: new vscode.ThemeIcon('folder'),
137-
tooltip: 'Remove Parent Folder from Context'
138-
}
139-
]
189+
buttons: has_parent_folder
190+
? [
191+
{
192+
iconPath: new vscode.ThemeIcon('folder'),
193+
tooltip: 'Remove Parent Folder from Context'
194+
}
195+
]
196+
: []
140197
}
141198
})
142199

@@ -146,6 +203,7 @@ export const remove_file_from_context_command = (
146203
return natural_sort(a.description || '', b.description || '')
147204
})
148205

206+
file_items_cache = items
149207
quick_pick.items = items
150208

151209
quick_pick.onDidAccept(async () => {
@@ -160,6 +218,9 @@ export const remove_file_from_context_command = (
160218
})
161219

162220
quick_pick.onDidHide(() => {
221+
if (is_showing_folder_quick_pick) {
222+
return
223+
}
163224
quick_pick.dispose()
164225
})
165226
}

0 commit comments

Comments
 (0)