-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore uneditable files in the file picker #767
Ignore uneditable files in the file picker #767
Conversation
Thanks a lot for sending in the pull request. It does seemed to be good to have a simple version like this without configuration at first. What is your use case? Currently ignore I wonder how |
@pickfire There are a number of cases I run into where this affects me:
|
I took a look at the binary detection stuff in ripgrep and it looks like it is indeed inspecting the contents and testing if it is text or not. How should this get brought in? It looks like that subcrate isn't really quite intended to be used outside of ripgrep itself yet. I would love to see the picker restrict itself to text files though, that would be a better approach than this pull request for sure. I've also learned a lot more about proper result/error propogation rather than the verbose match arms I used here, but I'm not motivated to refactor if a better approach is available. |
Looking further it looks like grep-searcher is already depended on in helix-term for global search. I'm not immediately certain how to pull in just the binary detection in the walk logic. It seems like it might be inefficient to build a searcher when we want all the files. |
Sorry for the delay, it seems I forgot to review the PR previously. I think this is a good first pass to eliminate potential matches ahead of time, for binary files we'll just handle those in the picker before rendering a preview. (We also want to filter any files over 20MB probably) |
If you think it's a good first pass then I'll refactor and rebase. Hopefully I can get to it this week. |
// We want to exclude files that the editor can't handle yet | ||
let mut type_builder = TypesBuilder::new(); | ||
let mut walk_builder = WalkBuilder::new(&root); | ||
let walk_builder = match type_builder.add( | ||
"compressed", | ||
"*.{zip,gz,bz2,zst,lzo,sz,tgz,tbz2,lz,lz4,lzma,lzo,z,Z,xz,7z,rar,cab}", | ||
) { | ||
Err(_) => &walk_builder, | ||
_ => { | ||
type_builder.negate("all"); | ||
let excluded_types = type_builder.build().unwrap(); | ||
walk_builder.types(excluded_types) | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// We want to exclude files that the editor can't handle yet | |
let mut type_builder = TypesBuilder::new(); | |
let mut walk_builder = WalkBuilder::new(&root); | |
let walk_builder = match type_builder.add( | |
"compressed", | |
"*.{zip,gz,bz2,zst,lzo,sz,tgz,tbz2,lz,lz4,lzma,lzo,z,Z,xz,7z,rar,cab}", | |
) { | |
Err(_) => &walk_builder, | |
_ => { | |
type_builder.negate("all"); | |
let excluded_types = type_builder.build().unwrap(); | |
walk_builder.types(excluded_types) | |
} | |
}; | |
// We want to exclude files that the editor can't handle yet | |
let mut type_builder = TypesBuilder::new(); | |
let mut walk_builder = WalkBuilder::new(&root); | |
let glob = "*.{zip,gz,bz2,zst,lzo,sz,tgz,tbz2,lz,lz4,lzma,lzo,z,Z,xz,7z,rar,cab}"; | |
let walk_builder = if type_builder.add("compressed", glob).is_ok() { | |
type_builder.negate("all"); | |
let excluded_types = type_builder.build().unwrap(); | |
walk_builder.types(excluded_types) | |
} else { | |
&walk_builder | |
}; |
Would this be better?
Possibly related sharkdp/fd#749 |
We don't use |
I meant the solutions they proposed. |
We'll basically do this: https://docs.rs/grep-searcher/0.1.8/grep_searcher/struct.BinaryDetection.html Pre-read a small buffer at the start of the file and scan for a |
This is probably incomplete, in that it only touches the file picker and not the suggestions in the
open
command, and it also only lists out common compressed file extensions. It should probably include a lot more things that are not editable, like iso, dmg, and more. I'm also unsure if this approach is preferred as file extension isn't 100% reliable, but I feel the blacklist approach is better than whitelist as we don't want to inadvertently prevent people from editing files that are perfectly editable.This is probably my first contributed rust code ever. I'm unsure if I did things the best way or not, so style critique is appreciated as well.