@@ -185,6 +185,22 @@ pub fn raw_regex_prompt(
185
185
cx. push_layer ( Box :: new ( prompt) ) ;
186
186
}
187
187
188
+ /// We want to exclude files that the editor can't handle yet
189
+ fn get_excluded_types ( ) -> ignore:: types:: Types {
190
+ use ignore:: types:: TypesBuilder ;
191
+ let mut type_builder = TypesBuilder :: new ( ) ;
192
+ type_builder
193
+ . add (
194
+ "compressed" ,
195
+ "*.{zip,gz,bz2,zst,lzo,sz,tgz,tbz2,lz,lz4,lzma,lzo,z,Z,xz,7z,rar,cab}" ,
196
+ )
197
+ . expect ( "Invalid type definition" ) ;
198
+ type_builder. negate ( "all" ) ;
199
+ type_builder
200
+ . build ( )
201
+ . expect ( "failed to build excluded_types" )
202
+ }
203
+
188
204
#[ derive( Debug ) ]
189
205
pub struct FilePickerData {
190
206
root : PathBuf ,
@@ -193,7 +209,7 @@ pub struct FilePickerData {
193
209
type FilePicker = Picker < PathBuf , FilePickerData > ;
194
210
195
211
pub fn file_picker ( editor : & Editor , root : PathBuf ) -> FilePicker {
196
- use ignore:: { types :: TypesBuilder , WalkBuilder } ;
212
+ use ignore:: WalkBuilder ;
197
213
use std:: time:: Instant ;
198
214
199
215
let config = editor. config ( ) ;
@@ -208,7 +224,8 @@ pub fn file_picker(editor: &Editor, root: PathBuf) -> FilePicker {
208
224
let absolute_root = root. canonicalize ( ) . unwrap_or_else ( |_| root. clone ( ) ) ;
209
225
210
226
let mut walk_builder = WalkBuilder :: new ( & root) ;
211
- walk_builder
227
+
228
+ let mut files = walk_builder
212
229
. hidden ( config. file_picker . hidden )
213
230
. parents ( config. file_picker . parents )
214
231
. ignore ( config. file_picker . ignore )
@@ -218,31 +235,18 @@ pub fn file_picker(editor: &Editor, root: PathBuf) -> FilePicker {
218
235
. git_exclude ( config. file_picker . git_exclude )
219
236
. sort_by_file_name ( |name1, name2| name1. cmp ( name2) )
220
237
. max_depth ( config. file_picker . max_depth )
221
- . filter_entry ( move |entry| filter_picker_entry ( entry, & absolute_root, dedup_symlinks) ) ;
222
-
223
- walk_builder. add_custom_ignore_filename ( helix_loader:: config_dir ( ) . join ( "ignore" ) ) ;
224
- walk_builder. add_custom_ignore_filename ( ".helix/ignore" ) ;
225
-
226
- // We want to exclude files that the editor can't handle yet
227
- let mut type_builder = TypesBuilder :: new ( ) ;
228
- type_builder
229
- . add (
230
- "compressed" ,
231
- "*.{zip,gz,bz2,zst,lzo,sz,tgz,tbz2,lz,lz4,lzma,lzo,z,Z,xz,7z,rar,cab}" ,
232
- )
233
- . expect ( "Invalid type definition" ) ;
234
- type_builder. negate ( "all" ) ;
235
- let excluded_types = type_builder
238
+ . filter_entry ( move |entry| filter_picker_entry ( entry, & absolute_root, dedup_symlinks) )
239
+ . add_custom_ignore_filename ( helix_loader:: config_dir ( ) . join ( "ignore" ) )
240
+ . add_custom_ignore_filename ( ".helix/ignore" )
241
+ . types ( get_excluded_types ( ) )
236
242
. build ( )
237
- . expect ( "failed to build excluded_types" ) ;
238
- walk_builder. types ( excluded_types) ;
239
- let mut files = walk_builder. build ( ) . filter_map ( |entry| {
240
- let entry = entry. ok ( ) ?;
241
- if !entry. file_type ( ) ?. is_file ( ) {
242
- return None ;
243
- }
244
- Some ( entry. into_path ( ) )
245
- } ) ;
243
+ . filter_map ( |entry| {
244
+ let entry = entry. ok ( ) ?;
245
+ if !entry. file_type ( ) ?. is_file ( ) {
246
+ return None ;
247
+ }
248
+ Some ( entry. into_path ( ) )
249
+ } ) ;
246
250
log:: debug!( "file_picker init {:?}" , Instant :: now( ) . duration_since( now) ) ;
247
251
248
252
let columns = [ PickerColumn :: new (
@@ -304,7 +308,7 @@ type FileExplorer = Picker<(PathBuf, bool), (PathBuf, Style)>;
304
308
305
309
pub fn file_explorer ( root : PathBuf , editor : & Editor ) -> Result < FileExplorer , std:: io:: Error > {
306
310
let directory_style = editor. theme . get ( "ui.text.directory" ) ;
307
- let directory_content = directory_content ( & root) ?;
311
+ let directory_content = directory_content ( & root, editor ) ?;
308
312
309
313
let columns = [ PickerColumn :: new (
310
314
"path" ,
@@ -350,21 +354,47 @@ pub fn file_explorer(root: PathBuf, editor: &Editor) -> Result<FileExplorer, std
350
354
Ok ( picker)
351
355
}
352
356
353
- fn directory_content ( path : & Path ) -> Result < Vec < ( PathBuf , bool ) > , std:: io:: Error > {
354
- let mut content: Vec < _ > = std:: fs:: read_dir ( path) ?
355
- . flatten ( )
356
- . map ( |entry| {
357
- (
358
- entry. path ( ) ,
359
- std:: fs:: metadata ( entry. path ( ) ) . is_ok_and ( |metadata| metadata. is_dir ( ) ) ,
360
- )
357
+ fn directory_content ( path : & Path , editor : & Editor ) -> Result < Vec < ( PathBuf , bool ) > , std:: io:: Error > {
358
+ use ignore:: WalkBuilder ;
359
+
360
+ let config = editor. config ( ) ;
361
+
362
+ let mut walk_builder = WalkBuilder :: new ( path) ;
363
+
364
+ let mut content: Vec < ( PathBuf , bool ) > = walk_builder
365
+ . hidden ( config. file_explorer . hidden )
366
+ . parents ( config. file_explorer . parents )
367
+ . ignore ( config. file_explorer . ignore )
368
+ . follow_links ( config. file_explorer . follow_symlinks )
369
+ . git_ignore ( config. file_explorer . git_ignore )
370
+ . git_global ( config. file_explorer . git_global )
371
+ . git_exclude ( config. file_explorer . git_exclude )
372
+ . max_depth ( Some ( 1 ) )
373
+ . add_custom_ignore_filename ( helix_loader:: config_dir ( ) . join ( "ignore" ) )
374
+ . add_custom_ignore_filename ( ".helix/ignore" )
375
+ . types ( get_excluded_types ( ) )
376
+ . build ( )
377
+ . filter_map ( |entry| {
378
+ entry
379
+ . map ( |entry| {
380
+ (
381
+ entry. path ( ) . to_path_buf ( ) ,
382
+ entry
383
+ . file_type ( )
384
+ . is_some_and ( |file_type| file_type. is_dir ( ) ) ,
385
+ )
386
+ } )
387
+ . ok ( )
388
+ . filter ( |entry| entry. 0 != path)
361
389
} )
362
390
. collect ( ) ;
363
391
364
392
content. sort_by ( |( path1, is_dir1) , ( path2, is_dir2) | ( !is_dir1, path1) . cmp ( & ( !is_dir2, path2) ) ) ;
393
+
365
394
if path. parent ( ) . is_some ( ) {
366
395
content. insert ( 0 , ( path. join ( ".." ) , true ) ) ;
367
396
}
397
+
368
398
Ok ( content)
369
399
}
370
400
0 commit comments