Skip to content

Commit 2c6b0d6

Browse files
committed
Integrate workspace provider into preview listeners to filter out ignored and excluded files
- Pass workspace_provider into setup_workspace_listeners in workspace-listener.ts (via preview.ts) and skip adding untracked files in onDidChangeTextDocument, onDidCreateFiles, onDidDeleteFiles, and onDidRenameFiles if workspace_provider.is_ignored_by_patterns(file_path) or workspace_provider.is_excluded(relative_path) returns true. - increase to 6px [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 │ │ ├── index.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 │ └── context │ ├── context-initialization.ts │ ├── helpers │ │ ├── get-all-workspace-files.ts │ │ └── get-selected-files.ts │ ├── providers │ │ ├── open-editors │ │ │ └── open-editors-provider.ts │ │ ├── selected-files │ │ │ └── selected-files-provider.ts │ │ └── workspace │ │ ├── modules │ │ │ ├── index.ts │ │ │ └── token-calculator.ts │ │ └── workspace-provider.ts │ ├── shared-context-state.ts │ └── utils │ └── shrink-file │ ├── index.ts │ ├── languages │ │ ├── c-style.ts │ │ ├── css.ts │ │ ├── html.ts │ │ ├── jsx.ts │ │ ├── python.ts │ │ ├── ruby.ts │ │ └── sql.ts │ ├── shrink-file.spec.ts │ ├── shrink-file.ts │ └── test-cases │ ├── c-style │ │ ├── input.txt │ │ └── output.txt │ ├── css │ │ ├── input.txt │ │ └── output.txt │ ├── html │ │ ├── input.txt │ │ └── output.txt │ ├── jsx │ │ ├── input.txt │ │ └── output.txt │ ├── python │ │ ├── input.txt │ │ └── output.txt │ ├── ruby │ │ ├── input.txt │ │ └── output.txt │ ├── scss │ │ ├── input.txt │ │ └── output.txt │ └── sql │ ├── input.txt │ └── output.txt └── packages └── ui └── src └── components └── editor └── prompt └── SelectedFiles ├── SelectedFiles.module.scss └── SelectedFiles.tsx
1 parent 5f957cb commit 2c6b0d6

4 files changed

Lines changed: 57 additions & 18 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export const preview_handler = async (params: {
4343
extension_context: params.extension_context,
4444
created_at: params.created_at,
4545
url: params.url,
46-
recent_api_configuration: params.recent_api_configuration
46+
recent_api_configuration: params.recent_api_configuration,
47+
workspace_provider: params.workspace_provider
4748
})
4849

4950
if (preview_result === null || preview_result.accepted_files.length == 0) {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { close_preview_diff_editors, show_diff_with_actions } from './vscode-ui'
1414
import { PreparedFile, PreviewableFile } from './types'
1515
import { ItemInPreview } from '@shared/types/file-in-preview'
16+
import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provider'
1617

1718
export const preview = async (params: {
1819
original_states: OriginalFileState[]
@@ -23,6 +24,7 @@ export const preview = async (params: {
2324
created_at?: number
2425
url?: string
2526
recent_api_configuration?: RecentApiConfiguration
27+
workspace_provider: WorkspaceProvider
2628
}): Promise<{
2729
accepted_files: PreviewableFile[]
2830
rejected_states: OriginalFileState[]
@@ -152,7 +154,8 @@ export const preview = async (params: {
152154
prompt_view_provider: params.prompt_view_provider,
153155
workspace_map,
154156
default_workspace,
155-
created_at: params.created_at
157+
created_at: params.created_at,
158+
workspace_provider: params.workspace_provider
156159
})
157160

158161
create_temp_files_with_original_content(prepared_files)

‎apps/editor/src/commands/apply-response-command/utils/preview/workspace-listener.ts‎

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { remove_directory_if_empty } from '../file-operations'
1010
import { ResponseHistoryItem } from '@shared/types/response-history-item'
1111
import { create_temp_files_with_original_content } from './temp-file-manager'
1212
import { normalize_path } from '@/utils/normalize-path'
13+
import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provider'
1314

1415
export let toggle_file_preview_state:
1516
| ((file: {
@@ -80,6 +81,7 @@ export const setup_workspace_listeners = (params: {
8081
workspace_map: Map<string, string>
8182
default_workspace: string
8283
created_at?: number
84+
workspace_provider: WorkspaceProvider
8385
}) => {
8486
const deleted_files_content_cache = new Map<string, string>()
8587

@@ -156,19 +158,26 @@ export const setup_workspace_listeners = (params: {
156158
const workspace_folder = vscode.workspace.getWorkspaceFolder(doc.uri)
157159
if (!workspace_folder) return
158160

161+
const file_path = doc.uri.fsPath
162+
const relative_path = normalize_path(
163+
vscode.workspace.asRelativePath(doc.uri, false)
164+
)
165+
166+
if (
167+
params.workspace_provider.is_ignored_by_patterns(file_path) ||
168+
params.workspace_provider.is_excluded(relative_path)
169+
) {
170+
return
171+
}
172+
159173
// Check if it's already added to avoid races
160174
if (
161-
params.prepared_files.some(
162-
(pf) => pf.sanitized_path == doc.uri.fsPath
163-
)
175+
params.prepared_files.some((pf) => pf.sanitized_path == file_path)
164176
) {
165177
return
166178
}
167179

168180
const new_content = doc.getText()
169-
const relative_path = normalize_path(
170-
vscode.workspace.asRelativePath(doc.uri, false)
171-
)
172181

173182
let original_content = ''
174183
let is_new = false
@@ -279,16 +288,25 @@ export const setup_workspace_listeners = (params: {
279288
const workspace_folder = vscode.workspace.getWorkspaceFolder(uri)
280289
if (!workspace_folder) continue
281290

291+
const file_path = uri.fsPath
292+
const relative_path = normalize_path(
293+
vscode.workspace.asRelativePath(uri, false)
294+
)
295+
296+
if (
297+
params.workspace_provider.is_ignored_by_patterns(file_path) ||
298+
params.workspace_provider.is_excluded(relative_path)
299+
) {
300+
continue
301+
}
302+
282303
if (
283-
params.prepared_files.some((pf) => pf.sanitized_path == uri.fsPath)
304+
params.prepared_files.some((pf) => pf.sanitized_path == file_path)
284305
) {
285306
continue
286307
}
287308

288309
const new_content = ''
289-
const relative_path = normalize_path(
290-
vscode.workspace.asRelativePath(uri, false)
291-
)
292310

293311
const original_content_for_undo =
294312
deleted_files_content_cache.get(uri.fsPath) ?? ''
@@ -377,9 +395,21 @@ export const setup_workspace_listeners = (params: {
377395
const workspace_folder = vscode.workspace.getWorkspaceFolder(uri)
378396
if (!workspace_folder) continue
379397

398+
const file_path = uri.fsPath
399+
const relative_path = normalize_path(
400+
vscode.workspace.asRelativePath(uri, false)
401+
)
402+
403+
if (
404+
params.workspace_provider.is_ignored_by_patterns(file_path) ||
405+
params.workspace_provider.is_excluded(relative_path)
406+
) {
407+
continue
408+
}
409+
380410
// Avoid duplicates if already tracked
381411
if (
382-
params.prepared_files.some((pf) => pf.sanitized_path === uri.fsPath)
412+
params.prepared_files.some((pf) => pf.sanitized_path === file_path)
383413
) {
384414
continue
385415
}
@@ -393,10 +423,6 @@ export const setup_workspace_listeners = (params: {
393423
new_content = ''
394424
}
395425

396-
const relative_path = normalize_path(
397-
vscode.workspace.asRelativePath(uri, false)
398-
)
399-
400426
const original_content = ''
401427
const is_new = true
402428

@@ -593,6 +619,15 @@ export const setup_workspace_listeners = (params: {
593619
})
594620
} else {
595621
// Not previously tracked: treat rename as delete (old) + create (new)
622+
if (
623+
params.workspace_provider.is_ignored_by_patterns(newUri.fsPath) ||
624+
params.workspace_provider.is_excluded(new_relative) ||
625+
params.workspace_provider.is_ignored_by_patterns(oldUri.fsPath) ||
626+
params.workspace_provider.is_excluded(old_relative)
627+
) {
628+
continue
629+
}
630+
596631
if (
597632
params.prepared_files.some(
598633
(pf) => pf.sanitized_path === newUri.fsPath

‎packages/ui/src/components/editor/prompt/SelectedFiles/SelectedFiles.module.scss‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@
5555

5656
.tokens {
5757
color: var(--cwc-text-color-dimmed);
58-
margin-left: 5px;
58+
margin-left: 6px;
5959
}

0 commit comments

Comments
 (0)