@@ -187,6 +187,22 @@ pub fn raw_regex_prompt(
187
187
cx. push_layer ( Box :: new ( prompt) ) ;
188
188
}
189
189
190
+ /// We want to exclude files that the editor can't handle yet
191
+ fn get_excluded_types ( ) -> ignore:: types:: Types {
192
+ use ignore:: types:: TypesBuilder ;
193
+ let mut type_builder = TypesBuilder :: new ( ) ;
194
+ type_builder
195
+ . add (
196
+ "compressed" ,
197
+ "*.{zip,gz,bz2,zst,lzo,sz,tgz,tbz2,lz,lz4,lzma,lzo,z,Z,xz,7z,rar,cab}" ,
198
+ )
199
+ . expect ( "Invalid type definition" ) ;
200
+ type_builder. negate ( "all" ) ;
201
+ type_builder
202
+ . build ( )
203
+ . expect ( "failed to build excluded_types" )
204
+ }
205
+
190
206
#[ derive( Debug ) ]
191
207
pub struct FilePickerData {
192
208
root : PathBuf ,
@@ -195,7 +211,7 @@ pub struct FilePickerData {
195
211
type FilePicker = Picker < PathBuf , FilePickerData > ;
196
212
197
213
pub fn file_picker ( editor : & Editor , root : PathBuf ) -> FilePicker {
198
- use ignore:: { types :: TypesBuilder , WalkBuilder } ;
214
+ use ignore:: WalkBuilder ;
199
215
use std:: time:: Instant ;
200
216
201
217
let config = editor. config ( ) ;
@@ -210,7 +226,8 @@ pub fn file_picker(editor: &Editor, root: PathBuf) -> FilePicker {
210
226
let absolute_root = root. canonicalize ( ) . unwrap_or_else ( |_| root. clone ( ) ) ;
211
227
212
228
let mut walk_builder = WalkBuilder :: new ( & root) ;
213
- walk_builder
229
+
230
+ let mut files = walk_builder
214
231
. hidden ( config. file_picker . hidden )
215
232
. parents ( config. file_picker . parents )
216
233
. ignore ( config. file_picker . ignore )
@@ -220,31 +237,18 @@ pub fn file_picker(editor: &Editor, root: PathBuf) -> FilePicker {
220
237
. git_exclude ( config. file_picker . git_exclude )
221
238
. sort_by_file_name ( |name1, name2| name1. cmp ( name2) )
222
239
. max_depth ( config. file_picker . max_depth )
223
- . filter_entry ( move |entry| filter_picker_entry ( entry, & absolute_root, dedup_symlinks) ) ;
224
-
225
- walk_builder. add_custom_ignore_filename ( helix_loader:: config_dir ( ) . join ( "ignore" ) ) ;
226
- walk_builder. add_custom_ignore_filename ( ".helix/ignore" ) ;
227
-
228
- // We want to exclude files that the editor can't handle yet
229
- let mut type_builder = TypesBuilder :: new ( ) ;
230
- type_builder
231
- . add (
232
- "compressed" ,
233
- "*.{zip,gz,bz2,zst,lzo,sz,tgz,tbz2,lz,lz4,lzma,lzo,z,Z,xz,7z,rar,cab}" ,
234
- )
235
- . expect ( "Invalid type definition" ) ;
236
- type_builder. negate ( "all" ) ;
237
- let excluded_types = type_builder
240
+ . filter_entry ( move |entry| filter_picker_entry ( entry, & absolute_root, dedup_symlinks) )
241
+ . add_custom_ignore_filename ( helix_loader:: config_dir ( ) . join ( "ignore" ) )
242
+ . add_custom_ignore_filename ( ".helix/ignore" )
243
+ . types ( get_excluded_types ( ) )
238
244
. build ( )
239
- . expect ( "failed to build excluded_types" ) ;
240
- walk_builder. types ( excluded_types) ;
241
- let mut files = walk_builder. build ( ) . filter_map ( |entry| {
242
- let entry = entry. ok ( ) ?;
243
- if !entry. file_type ( ) ?. is_file ( ) {
244
- return None ;
245
- }
246
- Some ( entry. into_path ( ) )
247
- } ) ;
245
+ . filter_map ( |entry| {
246
+ let entry = entry. ok ( ) ?;
247
+ if !entry. file_type ( ) ?. is_file ( ) {
248
+ return None ;
249
+ }
250
+ Some ( entry. into_path ( ) )
251
+ } ) ;
248
252
log:: debug!( "file_picker init {:?}" , Instant :: now( ) . duration_since( now) ) ;
249
253
250
254
let columns = [ PickerColumn :: new (
@@ -313,7 +317,7 @@ type FileExplorer = Picker<(PathBuf, bool), (PathBuf, Style)>;
313
317
314
318
pub fn file_explorer ( root : PathBuf , editor : & Editor ) -> Result < FileExplorer , std:: io:: Error > {
315
319
let directory_style = editor. theme . get ( "ui.text.directory" ) ;
316
- let directory_content = directory_content ( & root) ?;
320
+ let directory_content = directory_content ( & root, editor ) ?;
317
321
318
322
let columns = [ PickerColumn :: new (
319
323
"path" ,
@@ -373,21 +377,47 @@ pub fn file_explorer(root: PathBuf, editor: &Editor) -> Result<FileExplorer, std
373
377
Ok ( picker)
374
378
}
375
379
376
- fn directory_content ( path : & Path ) -> Result < Vec < ( PathBuf , bool ) > , std:: io:: Error > {
377
- let mut content: Vec < _ > = std:: fs:: read_dir ( path) ?
378
- . flatten ( )
379
- . map ( |entry| {
380
- (
381
- entry. path ( ) ,
382
- std:: fs:: metadata ( entry. path ( ) ) . is_ok_and ( |metadata| metadata. is_dir ( ) ) ,
383
- )
380
+ fn directory_content ( path : & Path , editor : & Editor ) -> Result < Vec < ( PathBuf , bool ) > , std:: io:: Error > {
381
+ use ignore:: WalkBuilder ;
382
+
383
+ let config = editor. config ( ) ;
384
+
385
+ let mut walk_builder = WalkBuilder :: new ( path) ;
386
+
387
+ let mut content: Vec < ( PathBuf , bool ) > = walk_builder
388
+ . hidden ( config. file_explorer . hidden )
389
+ . parents ( config. file_explorer . parents )
390
+ . ignore ( config. file_explorer . ignore )
391
+ . follow_links ( config. file_explorer . follow_symlinks )
392
+ . git_ignore ( config. file_explorer . git_ignore )
393
+ . git_global ( config. file_explorer . git_global )
394
+ . git_exclude ( config. file_explorer . git_exclude )
395
+ . max_depth ( Some ( 1 ) )
396
+ . add_custom_ignore_filename ( helix_loader:: config_dir ( ) . join ( "ignore" ) )
397
+ . add_custom_ignore_filename ( ".helix/ignore" )
398
+ . types ( get_excluded_types ( ) )
399
+ . build ( )
400
+ . filter_map ( |entry| {
401
+ entry
402
+ . map ( |entry| {
403
+ (
404
+ entry. path ( ) . to_path_buf ( ) ,
405
+ entry
406
+ . file_type ( )
407
+ . is_some_and ( |file_type| file_type. is_dir ( ) ) ,
408
+ )
409
+ } )
410
+ . ok ( )
411
+ . filter ( |entry| entry. 0 != path)
384
412
} )
385
413
. collect ( ) ;
386
414
387
415
content. sort_by ( |( path1, is_dir1) , ( path2, is_dir2) | ( !is_dir1, path1) . cmp ( & ( !is_dir2, path2) ) ) ;
416
+
388
417
if path. parent ( ) . is_some ( ) {
389
418
content. insert ( 0 , ( path. join ( ".." ) , true ) ) ;
390
419
}
420
+
391
421
Ok ( content)
392
422
}
393
423
0 commit comments