ivy.nvim/rust/finder.rs
Ade Attwood d60ba5085a fix: include dot files in search results
This adds dot files into the finder. We are adding the overrides to the
`ignore` package, that can be used later to add custom ignore
directories that can be passed in as settings.

We are also adding a new `ivy_cwd` function to libivy to get the current
directory due to the limitations of lua.

Fixes-issue: #16
2022-09-04 13:29:47 +01:00

34 lines
1 KiB
Rust

use ignore::{overrides::OverrideBuilder, WalkBuilder};
use std::fs;
pub struct Options {
pub directory: String,
}
pub fn find_files(options: Options) -> Vec<String> {
let mut files: Vec<String> = Vec::new();
let base_path = &fs::canonicalize(options.directory).unwrap();
let mut builder = WalkBuilder::new(base_path);
builder.hidden(false);
// TODO(ade): Remove unwraps and find a good way to get the errors into the UI. Currently there
// is no way to handel errors in the rust library
let mut override_builder = OverrideBuilder::new("");
override_builder.add("!.git").unwrap();
let overrides = override_builder.build().unwrap();
builder.overrides(overrides);
for result in builder.build() {
let absolute_candidate = result.unwrap();
let candidate_path = absolute_candidate.path().strip_prefix(base_path).unwrap();
if candidate_path.is_dir() {
continue;
}
files.push(candidate_path.to_str().unwrap().to_string());
}
files
}