Skip to content

Commit 88c9eae

Browse files
committed
Refactor file exclusion logic by moving default ignore patterns to a dedicated constant file and applying them consistently across all relevant utilities
1 parent f85d0a4 commit 88c9eae

7 files changed

Lines changed: 62 additions & 77 deletions

File tree

‎packages/vscode/package.json‎

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -540,52 +540,6 @@
540540
"codeWebChat.ignorePatterns": {
541541
"type": "array",
542542
"description": "List of glob patterns to ignore files and folders in the context.",
543-
"default": [
544-
"**/*.svg",
545-
"**/package-lock.json",
546-
"**/pnpm-lock.yaml",
547-
"**/*.png",
548-
"**/*.jpg",
549-
"**/*.jpeg",
550-
"**/*.gif",
551-
"**/*.bmp",
552-
"**/*.ico",
553-
"**/*.webp",
554-
"**/*.tiff",
555-
"**/*.psd",
556-
"**/*.avif",
557-
"**/*.mp4",
558-
"**/*.webm",
559-
"**/*.avi",
560-
"**/*.mov",
561-
"**/*.wmv",
562-
"**/*.flv",
563-
"**/*.mkv",
564-
"**/*.mp3",
565-
"**/*.wav",
566-
"**/*.ogg",
567-
"**/*.m4a",
568-
"**/*.aac",
569-
"**/*.flac",
570-
"**/*.zip",
571-
"**/*.rar",
572-
"**/*.7z",
573-
"**/*.tar",
574-
"**/*.gz",
575-
"**/*.bz2",
576-
"**/*.ttf",
577-
"**/*.otf",
578-
"**/*.woff",
579-
"**/*.woff2",
580-
"**/*.eot",
581-
"**/*.pdf",
582-
"**/*.exe",
583-
"**/*.dll",
584-
"**/*.so",
585-
"**/*.dylib",
586-
"**/*.bin",
587-
"**/*.vsidx"
588-
],
589543
"items": {
590544
"type": "string",
591545
"description": "A glob pattern."

‎packages/vscode/src/commands/checkpoints-command/utils/clean-directory.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ export const clean_directory = async (params: {
1212
const entry_uri = vscode.Uri.joinPath(params.dir_uri, name)
1313
const relative_path = path.relative(params.root_path, entry_uri.fsPath)
1414

15-
if (params.workspace_provider.is_excluded(relative_path)) {
16-
continue
17-
}
18-
1915
if (
20-
type != vscode.FileType.Directory &&
16+
params.workspace_provider.is_excluded(relative_path) ||
2117
params.workspace_provider.is_ignored_by_patterns(entry_uri.fsPath)
2218
) {
2319
continue

‎packages/vscode/src/commands/checkpoints-command/utils/copy-optimised-recursively.ts‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ const directory_contains_ignored = async (
1313
const entry_uri = vscode.Uri.joinPath(dir_uri, name)
1414
const relative_path = path.relative(root_path, entry_uri.fsPath)
1515

16-
if (workspace_provider.is_excluded(relative_path)) {
16+
if (
17+
workspace_provider.is_excluded(relative_path) ||
18+
workspace_provider.is_ignored_by_patterns(entry_uri.fsPath)
19+
) {
1720
return true
1821
}
1922

@@ -35,10 +38,6 @@ const directory_contains_ignored = async (
3538
) {
3639
return true
3740
}
38-
} else if (entry_stat.type == vscode.FileType.File) {
39-
if (workspace_provider.is_ignored_by_patterns(entry_uri.fsPath)) {
40-
return true
41-
}
4241
}
4342
}
4443
return false
@@ -51,7 +50,10 @@ export const copy_optimised_recursively = async (
5150
workspace_provider: WorkspaceProvider
5251
) => {
5352
const relative_path = path.relative(root_path, source_uri.fsPath)
54-
if (relative_path && workspace_provider.is_excluded(relative_path)) {
53+
if (
54+
(relative_path && workspace_provider.is_excluded(relative_path)) ||
55+
workspace_provider.is_ignored_by_patterns(source_uri.fsPath)
56+
) {
5557
return
5658
}
5759

@@ -89,9 +91,6 @@ export const copy_optimised_recursively = async (
8991
)
9092
}
9193
} else if (source_stat.type == vscode.FileType.File) {
92-
if (workspace_provider.is_ignored_by_patterns(source_uri.fsPath)) {
93-
return
94-
}
9594
await fs.copyFile(source_uri.fsPath, dest_uri.fsPath)
9695
}
9796
// Other file types are ignored. fs.stat resolves symlinks.

‎packages/vscode/src/commands/checkpoints-command/utils/sync-directory.ts‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,8 @@ export const sync_directory = async (params: {
3030
const dest_uri = vscode.Uri.joinPath(params.dest_dir, name)
3131
const relative_path = path.relative(params.root_path, dest_uri.fsPath)
3232

33-
if (params.workspace_provider.is_excluded(relative_path)) {
34-
continue
35-
}
36-
37-
let dest_stat
38-
try {
39-
dest_stat = await vscode.workspace.fs.stat(dest_uri)
40-
} catch (e) {
41-
continue
42-
}
43-
4433
if (
45-
dest_stat.type !== vscode.FileType.Directory &&
34+
params.workspace_provider.is_excluded(relative_path) ||
4635
params.workspace_provider.is_ignored_by_patterns(dest_uri.fsPath)
4736
) {
4837
continue
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
export const IGNORE_PATTERNS = [
2+
'**/package-lock.json',
3+
'**/pnpm-lock.yaml',
4+
'**/node_modules',
5+
'**/*.png',
6+
'**/*.jpg',
7+
'**/*.jpeg',
8+
'**/*.gif',
9+
'**/*.bmp',
10+
'**/*.ico',
11+
'**/*.webp',
12+
'**/*.tiff',
13+
'**/*.psd',
14+
'**/*.avif',
15+
'**/*.mp4',
16+
'**/*.webm',
17+
'**/*.avi',
18+
'**/*.mov',
19+
'**/*.wmv',
20+
'**/*.flv',
21+
'**/*.mkv',
22+
'**/*.mp3',
23+
'**/*.wav',
24+
'**/*.ogg',
25+
'**/*.m4a',
26+
'**/*.aac',
27+
'**/*.flac',
28+
'**/*.zip',
29+
'**/*.rar',
30+
'**/*.7z',
31+
'**/*.tar',
32+
'**/*.gz',
33+
'**/*.bz2',
34+
'**/*.ttf',
35+
'**/*.otf',
36+
'**/*.woff',
37+
'**/*.woff2',
38+
'**/*.eot',
39+
'**/*.pdf',
40+
'**/*.exe',
41+
'**/*.dll',
42+
'**/*.so',
43+
'**/*.dylib',
44+
'**/*.bin',
45+
'**/*.vsidx'
46+
]

‎packages/vscode/src/context/providers/workspace-provider.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fs from 'fs'
33
import * as path from 'path'
44
import ignore, { Ignore } from 'ignore'
55
import { CONTEXT_CHECKED_PATHS_STATE_KEY } from '../../constants/state-keys'
6+
import { IGNORE_PATTERNS } from '../../constants/ignore-patterns'
67
import { natural_sort } from '../../utils/natural-sort'
78
import { Logger } from '@shared/utils/logger'
89
import { display_token_count } from '@/utils/display-token-count'
@@ -1242,9 +1243,6 @@ export class WorkspaceProvider
12421243
}
12431244
}
12441245

1245-
// Add default exclusions (e.g., node_modules at the root)
1246-
this.combined_gitignore.add(['node_modules/'])
1247-
12481246
// After updating gitignore rules, clear token caches since exclusions may have changed
12491247
this.file_token_counts.clear()
12501248
this.directory_token_counts.clear()
@@ -1274,6 +1272,8 @@ export class WorkspaceProvider
12741272
this.user_ignore.add(patterns)
12751273
}
12761274

1275+
this.user_ignore.add(IGNORE_PATTERNS)
1276+
12771277
// Clear token caches since exclusions have changed
12781278
this.file_token_counts.clear()
12791279
this.directory_token_counts.clear()

‎packages/vscode/src/views/panel/backend/message-handlers/handle-commit-changes/utils/file-utils.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from 'path'
33
import * as fs from 'fs'
44
import { Logger } from '@shared/utils/logger'
55
import { GitRepository } from '@/utils/git-repository-utils'
6+
import { IGNORE_PATTERNS } from '@/constants/ignore-patterns'
67
import ignore from 'ignore'
78

89
export interface FileData {
@@ -20,8 +21,8 @@ export const collect_affected_files_with_metadata = async (params: {
2021
const staged_files = params.repository.state.indexChanges || []
2122
const files_data: FileData[] = []
2223
const config = vscode.workspace.getConfiguration('codeWebChat')
23-
const ignorePatterns = config.get<string[]>('ignorePatterns') ?? []
24-
const ig = ignore().add(ignorePatterns)
24+
const user_ignore_patterns = config.get<string[]>('ignorePatterns') ?? []
25+
const ig = ignore().add(user_ignore_patterns).add(IGNORE_PATTERNS)
2526

2627
for (const change of staged_files) {
2728
const file_path = change.uri.fsPath

0 commit comments

Comments
 (0)