@@ -4,7 +4,7 @@ import * as fs from "fs";
4
4
import * as path from "path" ;
5
5
import ignore from "ignore" ;
6
6
7
- export class FileTreeProvider implements vscode . TreeDataProvider < FileItem > {
7
+ export class FileTreeProvider implements vscode . TreeDataProvider < FileItem > , vscode . Disposable {
8
8
private _onDidChangeTreeData : vscode . EventEmitter <
9
9
FileItem | undefined | null | void
10
10
> = new vscode . EventEmitter < FileItem | undefined | null | void > ( ) ;
@@ -15,10 +15,36 @@ export class FileTreeProvider implements vscode.TreeDataProvider<FileItem> {
15
15
private workspaceRoot : string ;
16
16
private checkedItems : Map < string , vscode . TreeItemCheckboxState > = new Map ( ) ;
17
17
private gitignore = ignore ( ) ;
18
+ private ignoredExtensions : Set < string > = new Set ( ) ;
19
+ private watcher : vscode . FileSystemWatcher ;
18
20
19
21
constructor ( workspaceRoot : string ) {
20
22
this . workspaceRoot = workspaceRoot ;
21
23
this . loadGitignore ( ) ;
24
+ this . loadIgnoredExtensions ( ) ;
25
+
26
+ // Create a file system watcher
27
+ this . watcher = vscode . workspace . createFileSystemWatcher ( '**/*' ) ;
28
+
29
+ this . watcher . onDidCreate ( ( uri ) => this . onFileSystemChanged ( uri ) ) ;
30
+ this . watcher . onDidDelete ( ( uri ) => this . onFileSystemChanged ( uri ) ) ;
31
+ this . watcher . onDidChange ( ( uri ) => this . onFileSystemChanged ( uri ) ) ;
32
+
33
+ // Listen for configuration changes
34
+ vscode . workspace . onDidChangeConfiguration ( ( event ) => {
35
+ if ( event . affectsConfiguration ( "files2prompt.ignoredExtensions" ) ) {
36
+ this . loadIgnoredExtensions ( ) ;
37
+ this . refresh ( ) ;
38
+ }
39
+ } ) ;
40
+ }
41
+
42
+ public dispose ( ) : void {
43
+ this . watcher . dispose ( ) ;
44
+ }
45
+
46
+ private onFileSystemChanged ( uri : vscode . Uri ) : void {
47
+ this . refresh ( ) ;
22
48
}
23
49
24
50
refresh ( ) : void {
@@ -67,17 +93,21 @@ export class FileTreeProvider implements vscode.TreeDataProvider<FileItem> {
67
93
const uri = vscode . Uri . file ( fullPath ) ;
68
94
const isDirectory = entry . isDirectory ( ) ;
69
95
70
- const isIgnored = this . isGitIgnored ( relativePath ) ;
96
+ const extension = path . extname ( entry . name ) . toLowerCase ( ) . replace ( "." , "" ) ;
97
+ const isIgnoredExtension = this . ignoredExtensions . has ( extension ) ;
98
+ const isGitIgnored = this . isGitIgnored ( relativePath ) ;
71
99
72
- let checkboxState = this . checkedItems . get ( fullPath ) ;
100
+ const key = fullPath ;
101
+ let checkboxState = this . checkedItems . get ( key ) ;
73
102
74
103
if ( checkboxState === undefined ) {
75
104
const parentPath = path . dirname ( fullPath ) ;
76
105
const parentCheckboxState = this . checkedItems . get ( parentPath ) ;
77
106
78
107
if (
79
108
parentCheckboxState === vscode . TreeItemCheckboxState . Checked &&
80
- ! isIgnored
109
+ ! isGitIgnored &&
110
+ ! isIgnoredExtension
81
111
) {
82
112
checkboxState = vscode . TreeItemCheckboxState . Checked ;
83
113
this . checkedItems . set ( fullPath , checkboxState ) ;
@@ -94,7 +124,7 @@ export class FileTreeProvider implements vscode.TreeDataProvider<FileItem> {
94
124
: vscode . TreeItemCollapsibleState . None ,
95
125
isDirectory ,
96
126
checkboxState ,
97
- isIgnored
127
+ isGitIgnored || isIgnoredExtension
98
128
) ;
99
129
100
130
items . push ( item ) ;
@@ -138,8 +168,11 @@ export class FileTreeProvider implements vscode.TreeDataProvider<FileItem> {
138
168
const siblingPath = path . join ( dirPath , entry . name ) ;
139
169
const relativePath = path . relative ( this . workspaceRoot , siblingPath ) ;
140
170
141
- if ( this . isGitIgnored ( relativePath ) ) {
142
- continue ; // Skip gitignored items
171
+ const extension = path . extname ( entry . name ) . toLowerCase ( ) . replace ( "." , "" ) ;
172
+ const isIgnoredExtension = this . ignoredExtensions . has ( extension ) ;
173
+
174
+ if ( this . isGitIgnored ( relativePath ) || isIgnoredExtension ) {
175
+ continue ; // Skip gitignored items and ignored extensions
143
176
}
144
177
145
178
hasNonIgnoredChild = true ;
@@ -180,8 +213,11 @@ export class FileTreeProvider implements vscode.TreeDataProvider<FileItem> {
180
213
const relativePath = path . relative ( this . workspaceRoot , fullPath ) ;
181
214
const isGitIgnored = this . isGitIgnored ( relativePath ) ;
182
215
183
- if ( ! parentIsGitIgnored && isGitIgnored ) {
184
- // Skip gitignored items when parent is not gitignored
216
+ const extension = path . extname ( entry . name ) . toLowerCase ( ) . replace ( "." , "" ) ;
217
+ const isIgnoredExtension = this . ignoredExtensions . has ( extension ) ;
218
+
219
+ if ( ! parentIsGitIgnored && ( isGitIgnored || isIgnoredExtension ) ) {
220
+ // Skip gitignored items and ignored extensions when parent is not gitignored
185
221
continue ;
186
222
}
187
223
@@ -241,6 +277,18 @@ export class FileTreeProvider implements vscode.TreeDataProvider<FileItem> {
241
277
private isGitIgnored ( relativePath : string ) : boolean {
242
278
return this . gitignore . ignores ( relativePath ) ;
243
279
}
280
+
281
+ private loadIgnoredExtensions ( ) {
282
+ const config = vscode . workspace . getConfiguration ( "files2prompt" ) ;
283
+ const extensionsString = config . get < string > (
284
+ "ignoredExtensions" ,
285
+ "png,jpg,jpeg,gif,svg"
286
+ ) ;
287
+ const extensionsArray = extensionsString
288
+ . split ( "," )
289
+ . map ( ( ext ) => ext . trim ( ) . toLowerCase ( ) ) ;
290
+ this . ignoredExtensions = new Set ( extensionsArray ) ;
291
+ }
244
292
}
245
293
246
294
export class FileItem extends vscode . TreeItem {
0 commit comments