Skip to content

Commit cf4d4a0

Browse files
committed
Implement interactive search prompt for relevant files during response application
- add internal command to 'search files commands' that allows providing results set (array of file objects (path, checked state)) in param. Use it in 'apply response command', in place of the current flow that uses prompt view. - when using 'codeWebChat.internal.searchFilesWithResults', don't send response to the panel (remove any leftover logic of not using panel for file search anymore) - it's been reported that 'search in results' doesn't work when invoked with [Fragment] └── apps └── editor └── src ├── commands │ ├── apply-response-command │ │ ├── apply-response-command.ts │ │ ├── handlers │ │ │ ├── diff-handler.ts │ │ │ ├── fast-replace-handler.ts │ │ │ ├── restore-preview-handler.ts │ │ │ ├── search-replace-handler.ts │ │ │ └── truncated-handler.ts │ │ ├── response-processor.ts │ │ ├── types │ │ │ └── original-file-state.ts │ │ └── utils │ │ ├── file-checks.ts │ │ ├── file-operations.ts │ │ ├── preview │ │ │ ├── diff-utils.ts │ │ │ ├── file-preparer.ts │ │ │ ├── index.ts │ │ │ ├── preview.ts │ │ │ ├── temp-file-manager.ts │ │ │ ├── types.ts │ │ │ ├── virtual-document-provider.ts │ │ │ ├── vscode-ui.ts │ │ │ └── workspace-listener.ts │ │ ├── preview-handler.ts │ │ └── state-manager.ts │ ├── generate-commit-message-commands │ │ └── generate-commit-message-commands.ts │ └── search-files-commands.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 │ └── perform-semantic-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-provided-results.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 └── search-files-by-semantic.ts
1 parent 3df6097 commit cf4d4a0

5 files changed

Lines changed: 280 additions & 84 deletions

File tree

‎apps/editor/src/commands/apply-response-command/apply-response-command.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ export const apply_response_command = (params: {
115115
workspace_files
116116
})
117117

118-
if (resolve_fn) {
118+
const is_relevant_files = response_items.some(
119+
(i) => i.type == 'relevant-files'
120+
)
121+
122+
if (resolve_fn && !is_relevant_files) {
119123
const history = params.prompt_view_provider.response_history
120124

121125
let created_at_for_switch: number
@@ -184,9 +188,6 @@ export const apply_response_command = (params: {
184188
let saved_tab_groups: SavedTabGroups | undefined
185189

186190
try {
187-
const is_relevant_files = response_items.some(
188-
(i) => i.type == 'relevant-files'
189-
)
190191
if (!is_relevant_files) {
191192
// Save current tab groups before entering preview
192193
saved_tab_groups = {

‎apps/editor/src/commands/apply-response-command/response-processor.ts‎

Lines changed: 13 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ import { handle_truncated_edit } from './handlers/truncated-handler'
2828
import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provider'
2929
import { natural_sort } from '@/utils/natural-sort'
3030
import { t } from '@/i18n'
31-
import {
32-
RelevantFileInPreview,
33-
ItemInPreview
34-
} from '@shared/types/file-in-preview'
35-
import { PreviewDecision } from './utils/preview/types'
36-
import { set_response_preview_promise_resolve } from './utils/preview/preview'
31+
import { RelevantFileInPreview } from '@shared/types/file-in-preview'
3732
import { is_truncation_line } from '@/utils/changes-integration/truncations-processor/utils/is-truncation-line'
3833

3934
export type PreviewData = {
@@ -119,7 +114,6 @@ export const process_response = async (params: {
119114
const workspace_roots = params.workspace_provider.get_workspace_roots()
120115

121116
const files_for_preview: RelevantFileInPreview[] = []
122-
const items_for_preview: ItemInPreview[] = []
123117

124118
for (const item of params.response_items) {
125119
if (item.type == 'relevant-files') {
@@ -180,71 +174,24 @@ export const process_response = async (params: {
180174

181175
local_files.sort((a, b) => natural_sort(a.file_path, b.file_path))
182176
files_for_preview.push(...local_files)
183-
items_for_preview.push(...local_files)
184-
} else if (item.type == 'text') {
185-
items_for_preview.push({
186-
type: 'text',
187-
content: item.content
188-
})
189-
} else if (item.type == 'inline-file') {
190-
items_for_preview.push({
191-
type: 'inline-file',
192-
content: item.content,
193-
language: item.language
194-
})
195177
}
196178
}
197179

198-
const created_at_for_preview = params.args?.created_at ?? Date.now()
199-
200-
const history = params.prompt_view_provider.response_history
201-
if (!params.args?.created_at) {
202-
const new_item = {
203-
response: params.response,
204-
raw_instructions: params.args?.raw_instructions,
205-
created_at: created_at_for_preview,
206-
relevant_files: files_for_preview,
207-
url: params.args?.url,
208-
recent_api_configuration: params.args?.recent_api_configuration
209-
}
210-
history.push(new_item)
211-
} else {
212-
const existing = history.find(
213-
(i) => i.created_at === params.args!.created_at
214-
)
215-
if (existing) {
216-
existing.relevant_files = files_for_preview
217-
}
218-
}
219-
params.prompt_view_provider.send_message({
220-
command: 'RESPONSE_HISTORY',
221-
history
222-
})
223-
224180
params.prompt_view_provider.send_message({
225181
command: 'HIDE_PROGRESS'
226182
})
227183

228-
params.prompt_view_provider.send_message({
229-
command: 'RESPONSE_PREVIEW_STARTED',
230-
items: items_for_preview,
231-
raw_instructions: params.args?.raw_instructions,
232-
created_at: created_at_for_preview,
233-
url: params.args?.url,
234-
recent_api_configuration: params.args?.recent_api_configuration
235-
})
236-
237-
const decision = await new Promise<PreviewDecision>((resolve) => {
238-
set_response_preview_promise_resolve(resolve)
239-
}).finally(() => {
240-
set_response_preview_promise_resolve(undefined)
241-
})
242-
243-
params.prompt_view_provider.send_message({
244-
command: 'RESPONSE_PREVIEW_FINISHED'
245-
})
184+
const decision = await vscode.commands.executeCommand<
185+
{ selected_paths: string[]; matched_paths: string[] } | undefined
186+
>(
187+
'codeWebChat.internal.searchFilesWithResults',
188+
files_for_preview.map((f) => ({
189+
path: f.absolute_path,
190+
checked: f.is_checked
191+
}))
192+
)
246193

247-
if ('accepted_files' in decision && decision.accepted_files.length > 0) {
194+
if (decision) {
248195
const shared_context_state =
249196
params.prompt_view_provider.shared_context_state
250197
const was_frf = params.workspace_provider.is_frf_mode
@@ -253,9 +200,8 @@ export const process_response = async (params: {
253200
shared_context_state.switch_context_state(false)
254201
}
255202

256-
const accepted_files = decision.accepted_files as RelevantFileInPreview[]
257-
const presented_files = files_for_preview.map((f) => f.absolute_path!)
258-
const selected_files = accepted_files.map((f) => f.absolute_path!)
203+
const selected_files = decision.selected_paths
204+
const presented_files = decision.matched_paths
259205

260206
const filtered_current_files = current_checked_files.filter(
261207
(f) => !presented_files.includes(f)
@@ -277,16 +223,6 @@ export const process_response = async (params: {
277223
})
278224

279225
await params.prompt_view_provider.switch_to_edit_files()
280-
} else if ('created_at' in decision && decision.created_at) {
281-
const history = params.prompt_view_provider.response_history
282-
const new_history = history.filter(
283-
(item) => item.created_at !== created_at_for_preview
284-
)
285-
params.prompt_view_provider.response_history = new_history
286-
params.prompt_view_provider.send_message({
287-
command: 'RESPONSE_HISTORY',
288-
history: new_history
289-
})
290226
}
291227

292228
return null

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Logger } from '@shared/utils/logger'
66
import { dictionary } from '@shared/constants/dictionary'
77
import { t } from '@/i18n'
88
import { search_files } from '@/features/search-files'
9+
import { prompt_for_provided_results } from '@/features/search-files/utils/prompt-for-provided-results'
910

1011
export const get_target_folder_path = async (
1112
item?: any
@@ -129,6 +130,37 @@ export const search_files_commands = (
129130
vscode.commands.registerCommand(
130131
'codeWebChat.searchFilesFromFile',
131132
(item: any) => search_handler(item)
133+
),
134+
vscode.commands.registerCommand(
135+
'codeWebChat.internal.searchFilesWithResults',
136+
async (files: { path: string; checked: boolean }[]) => {
137+
while (true) {
138+
const result = await prompt_for_provided_results({
139+
files,
140+
workspace_provider
141+
})
142+
143+
if (!result) return undefined
144+
145+
if ('action' in result) {
146+
const sub_search_result = await search_files({
147+
get_files: async () => result.matched_paths,
148+
workspace_provider,
149+
extension_context,
150+
show_back_button: true,
151+
is_sub_search: true
152+
})
153+
154+
if (sub_search_result === 'back') {
155+
continue
156+
}
157+
158+
return sub_search_result
159+
}
160+
161+
return result
162+
}
163+
}
132164
)
133165
]
134166
}

‎apps/editor/src/extension.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ import {
3333
generate_commit_message_commands,
3434
set_ranges_command,
3535
search_files_commands,
36-
select_referencing_files_commands,
3736
select_definition_file_command,
3837
select_unstaged_files_command,
3938
select_commit_files_command,
4039
select_clipboard_paths_command,
4140
select_changed_files_command,
42-
select_parent_folder_command
41+
select_parent_folder_command,
42+
select_referencing_files_commands
4343
} from './commands'
4444
import { setup_git_discard_file_watcher } from './services/git-discard-file-watcher'
4545
import { select_imported_files_command } from './commands/select-imported-files-command'
@@ -178,7 +178,7 @@ export const activate = async (extension_context: vscode.ExtensionContext) => {
178178
workspace_provider,
179179
extension_context
180180
),
181-
...select_referencing_files_commands(workspace_provider, extension_context),
181+
// ...select_referencing_files_commands(workspace_provider, extension_context),
182182
...search_files_commands(workspace_provider, extension_context),
183183
select_definition_file_command(workspace_provider),
184184
open_url_command({

0 commit comments

Comments
 (0)