Skip to content

Commit 86d06da

Browse files
committed
Implement relevant files selection to filter and merge context files before previewing chat responses
- when applying relevant paths from the response, merge them with the 'regular checked items' (not frf, even if frf is active) - when applying 'relevant paths' instead of replacing, merge. - when 'relevant files' are applied we show confirmation quick pick - display only paths from the response, all checked by default - when the response is 'relevant files' we see ongoing 'Preparing response preview' modal. Should have other text: 'Waiting for confirmation...' - when 'relevant files', don't create checkpoint or show 'Preparing response preview' modal - when 'relevant files', when a file was checked before but user unchecked it, it should get unchecked - add missing translations
1 parent 0265e10 commit 86d06da

4 files changed

Lines changed: 116 additions & 81 deletions

File tree

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

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
preview_document_provider,
2727
CwcPreviewProvider
2828
} from './utils/preview/virtual-document-provider'
29+
import { parse_response } from './utils/clipboard-parser'
2930

3031
let in_progress = false
3132
let placeholder_created_at_for_update: number | undefined
@@ -84,7 +85,17 @@ export const apply_chat_response_command = (params: {
8485
return
8586
}
8687

87-
if (response_preview_promise_resolve) {
88+
const is_single_root_folder_workspace =
89+
(vscode.workspace.workspaceFolders?.length ?? 0) <= 1
90+
const clipboard_items = parse_response({
91+
response: chat_response,
92+
is_single_root_folder_workspace
93+
})
94+
const is_relevant_files = clipboard_items.some(
95+
(item) => item.type == 'relevant-files'
96+
)
97+
98+
if (response_preview_promise_resolve && !is_relevant_files) {
8899
const history = params.panel_provider.response_history
89100

90101
const new_item: ResponseHistoryItem = {
@@ -131,37 +142,39 @@ export const apply_chat_response_command = (params: {
131142
let saved_tab_groups: SavedTabGroups | undefined
132143

133144
try {
134-
// Save current tab groups before entering preview
135-
saved_tab_groups = {
136-
editors: [],
137-
active_editor_uri:
138-
vscode.window.activeTextEditor?.document.uri.toString()
139-
}
145+
if (!is_relevant_files) {
146+
// Save current tab groups before entering preview
147+
saved_tab_groups = {
148+
editors: [],
149+
active_editor_uri:
150+
vscode.window.activeTextEditor?.document.uri.toString()
151+
}
140152

141-
for (const tab_group of vscode.window.tabGroups.all) {
142-
for (const tab of tab_group.tabs) {
143-
if (tab.input instanceof vscode.TabInputText) {
144-
saved_tab_groups.editors.push({
145-
uri: tab.input.uri.toString(),
146-
view_column: tab_group.viewColumn,
147-
is_active: tab.isActive
148-
})
153+
for (const tab_group of vscode.window.tabGroups.all) {
154+
for (const tab of tab_group.tabs) {
155+
if (tab.input instanceof vscode.TabInputText) {
156+
saved_tab_groups.editors.push({
157+
uri: tab.input.uri.toString(),
158+
view_column: tab_group.viewColumn,
159+
is_active: tab.isActive
160+
})
161+
}
149162
}
150163
}
151-
}
152164

153-
params.panel_provider.send_message({
154-
command: 'SHOW_PROGRESS',
155-
title: t('common.progress.preparing-preview')
156-
})
165+
params.panel_provider.send_message({
166+
command: 'SHOW_PROGRESS',
167+
title: t('common.progress.preparing-preview')
168+
})
157169

158-
before_checkpoint = await create_checkpoint({
159-
workspace_provider: params.workspace_provider,
160-
context: params.context,
161-
panel_provider: params.panel_provider,
162-
trigger: 'before-response-previewed',
163-
description: args?.raw_instructions
164-
})
170+
before_checkpoint = await create_checkpoint({
171+
workspace_provider: params.workspace_provider,
172+
context: params.context,
173+
panel_provider: params.panel_provider,
174+
trigger: 'before-response-previewed',
175+
description: args?.raw_instructions
176+
})
177+
}
165178

166179
const preview_data = await process_chat_response(
167180
args,

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

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provi
3030
import { natural_sort } from '@/utils/natural-sort'
3131
import { t } from '@/i18n'
3232
import { is_truncation_line } from './utils/edit-formats/truncations'
33+
import { SharedFileState } from '@/context/shared-file-state'
3334

3435
export type PreviewData = {
3536
original_states: OriginalFileState[]
@@ -115,25 +116,17 @@ export const process_chat_response = async (
115116
(item) => item.type == 'relevant-files'
116117
) as RelevantFilesItem
117118

118-
const current_checked_files = workspace_provider.get_checked_files()
119-
const relevant_paths_normalized = new Set(
120-
relevant_files_item.file_paths.map((p) => p.replace(/\\/g, '/'))
121-
)
119+
panel_provider.send_message({
120+
command: 'SHOW_PROGRESS',
121+
title: 'Waiting for confirmation...'
122+
})
123+
124+
const current_checked_files =
125+
workspace_provider.get_export_state().regular.checked_files
122126

123127
const workspace_roots = workspace_provider.get_workspace_roots()
124128
const all_paths_to_process = new Set<string>(relevant_files_item.file_paths)
125129

126-
for (const file_path of current_checked_files) {
127-
const workspace_root =
128-
workspace_provider.get_workspace_root_for_file(file_path)
129-
if (workspace_root) {
130-
const relative_path = path
131-
.relative(workspace_root, file_path)
132-
.replace(/\\/g, '/')
133-
all_paths_to_process.add(relative_path)
134-
}
135-
}
136-
137130
const open_file_button = {
138131
iconPath: new vscode.ThemeIcon('go-to-file'),
139132
tooltip: t('common.go-to-file')
@@ -165,7 +158,7 @@ export const process_chat_response = async (
165158
description: display_dir
166159
? `${token_info} · ${display_dir}`
167160
: token_info,
168-
picked: relevant_paths_normalized.has(rel_path),
161+
picked: true,
169162
file_path: absolute_path,
170163
relative_path: rel_path,
171164
buttons: [open_file_button]
@@ -239,7 +232,7 @@ export const process_chat_response = async (
239232
quick_pick.show()
240233
})
241234

242-
if (selected_items && selected_items.length > 0) {
235+
if (selected_items) {
243236
const files_to_check: string[] = []
244237

245238
for (const selection of selected_items) {
@@ -248,12 +241,36 @@ export const process_chat_response = async (
248241
}
249242
}
250243

251-
if (files_to_check.length > 0) {
252-
await workspace_provider.set_checked_files(files_to_check)
253-
vscode.window.showInformationMessage(
254-
t('command.apply-chat-response.context-pruning.success')
255-
)
244+
const presented_files: string[] = []
245+
for (const item of quick_pick_items) {
246+
if (item.file_path) {
247+
presented_files.push(item.file_path)
248+
}
256249
}
250+
251+
const shared_state = SharedFileState.get_instance()
252+
const was_frf = workspace_provider.is_frf_mode
253+
254+
if (was_frf) {
255+
shared_state.switch_context_state(false)
256+
}
257+
258+
const filtered_current_files = current_checked_files.filter(
259+
(f) => !presented_files.includes(f)
260+
)
261+
262+
const merged_files = Array.from(
263+
new Set([...filtered_current_files, ...files_to_check])
264+
)
265+
await workspace_provider.set_checked_files(merged_files)
266+
267+
if (was_frf) {
268+
shared_state.switch_context_state(true)
269+
}
270+
271+
vscode.window.showInformationMessage(
272+
t('command.apply-chat-response.context-pruning.success')
273+
)
257274
}
258275

259276
return null

‎apps/editor/src/context/providers/workspace/workspace-provider.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface IWorkspaceProvider {
3535
}
3636
frf: { checked_files: string[]; checked_timestamps: Record<string, number> }
3737
}
38+
readonly is_frf_mode: boolean
3839
}
3940

4041
export class WorkspaceProvider
@@ -65,6 +66,10 @@ export class WorkspaceProvider
6566
}
6667
private _is_frf_mode: boolean = false
6768

69+
public get is_frf_mode(): boolean {
70+
return this._is_frf_mode
71+
}
72+
6873
private get _checked_items() {
6974
return this._is_frf_mode
7075
? this._frf_state.checked_items

‎apps/editor/src/i18n/translations/commands/apply-chat-response.ts‎

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,40 +54,40 @@ export const apply_chat_response = {
5454
bg: 'Прилагане с Интелигентно актуализиране'
5555
},
5656
'command.apply-chat-response.context-pruning.title': {
57-
en: 'Find Relevant Files',
58-
pl: 'Znajdowanie odpowiednich plików',
59-
'zh-cn': '查找相关文件',
60-
ja: '関連ファイルの検索',
61-
'zh-tw': '尋找相關檔案',
62-
de: 'Relevante Dateien finden',
63-
es: 'Buscar archivos relevantes',
64-
fr: 'Trouver les fichiers pertinents',
65-
'pt-br': 'Encontrar arquivos relevantes',
66-
ru: 'Поиск соответствующих файлов',
67-
ko: '관련 파일 찾기',
68-
it: 'Trova file rilevanti',
69-
tr: 'İlgili Dosyaları Bul',
70-
cs: 'Najít relevantní soubory',
71-
hu: 'Releváns fájlok keresése',
72-
bg: 'Намиране на съответните файлове'
57+
en: 'Relevant Files',
58+
pl: 'Pasujące pliki',
59+
'zh-cn': '相关文件',
60+
ja: '関連ファイル',
61+
'zh-tw': '相關檔案',
62+
de: 'Relevante Dateien',
63+
es: 'Archivos relevantes',
64+
fr: 'Fichiers pertinents',
65+
'pt-br': 'Arquivos relevantes',
66+
ru: 'Соответствующие файлы',
67+
ko: '관련 파일',
68+
it: 'File rilevanti',
69+
tr: 'İlgili Dosyalar',
70+
cs: 'Relevantní soubory',
71+
hu: 'Releváns fájlok',
72+
bg: 'Съответни файлове'
7373
},
7474
'command.apply-chat-response.context-pruning.placeholder': {
75-
en: 'Confirm relevant files',
76-
pl: 'Potwierdź odpowiednie pliki',
77-
'zh-cn': '确认相关文件',
78-
ja: '関連ファイルを確認',
79-
'zh-tw': '確認相關檔案',
80-
de: 'Relevante Dateien bestätigen',
81-
es: 'Confirmar archivos relevantes',
82-
fr: 'Confirmer les fichiers pertinents',
83-
'pt-br': 'Confirmar arquivos relevantes',
84-
ru: 'Подтвердить соответствующие файлы',
85-
ko: '관련 파일 확인',
86-
it: 'Conferma file rilevanti',
87-
tr: 'İlgili dosyaları onayla',
88-
cs: 'Potvrdit relevantní soubory',
89-
hu: 'Releváns fájlok megerősítése',
90-
bg: 'Потвърдете съответните файлове'
75+
en: 'Confirm files to include in context',
76+
pl: 'Wybierz pliki do zaznaczenia w kontekście',
77+
'zh-cn': '确认要包含在上下文中的文件',
78+
ja: 'コンテキストに含めるファイルを確認',
79+
'zh-tw': '確認要包含在上下文中的檔案',
80+
de: 'Bestätigen Sie die Dateien, die in den Kontext aufgenommen werden sollen',
81+
es: 'Confirmar archivos para incluir en el contexto',
82+
fr: 'Confirmer les fichiers à inclure dans le contexte',
83+
'pt-br': 'Confirmar arquivos para incluir no contexto',
84+
ru: 'Подтвердите файлы для включения в контекст',
85+
ko: '컨텍스트에 포함할 파일 확인',
86+
it: 'Conferma i file da includere nel contesto',
87+
tr: 'Bağlama dahil edilecek dosyaları onaylayın',
88+
cs: 'Potvrďte soubory, které chcete zahrnout do kontextu',
89+
hu: 'Erősítse meg a kontextusba foglalandó fájlokat',
90+
bg: 'Потвърдете файловете за включване в контекста'
9191
},
9292
'command.apply-chat-response.context-pruning.success': {
9393
en: 'Relevant files found successfully.',

0 commit comments

Comments
 (0)