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
This commit is contained in:
Ade Attwood 2022-09-04 13:10:11 +01:00
parent 252fc9da1d
commit d60ba5085a
4 changed files with 31 additions and 2 deletions

View file

@ -8,6 +8,7 @@ local ivy_c = ffi.load(library_path)
ffi.cdef [[ ffi.cdef [[
void ivy_init(const char*); void ivy_init(const char*);
char* ivy_cwd();
int ivy_match(const char*, const char*); int ivy_match(const char*, const char*);
char* ivy_files(const char*, const char*); char* ivy_files(const char*, const char*);
]] ]]
@ -18,6 +19,10 @@ libivy.ivy_init = function(dir)
ivy_c.ivy_init(dir) ivy_c.ivy_init(dir)
end end
libivy.ivy_cwd = function ()
return ffi.string(ivy_c.ivy_cwd())
end
libivy.ivy_match = function(pattern, text) libivy.ivy_match = function(pattern, text)
return ivy_c.ivy_match(pattern, text) return ivy_c.ivy_match(pattern, text)
end end

View file

@ -7,3 +7,12 @@ it("should run a simple match", function(t)
t.error("Score should not be less than 0 found " .. score) t.error("Score should not be less than 0 found " .. score)
end end
end) end)
it("should find a dot file", function (t)
local current_dir = libivy.ivy_cwd()
local matches = libivy.ivy_files("ci.yml", current_dir);
if matches ~= ".github/workflows/ci.yml\n" then
t.error("Invalid matches: " .. matches)
end
end);

View file

@ -1,4 +1,4 @@
use ignore::WalkBuilder; use ignore::{overrides::OverrideBuilder, WalkBuilder};
use std::fs; use std::fs;
pub struct Options { pub struct Options {
@ -10,7 +10,15 @@ pub fn find_files(options: Options) -> Vec<String> {
let base_path = &fs::canonicalize(options.directory).unwrap(); let base_path = &fs::canonicalize(options.directory).unwrap();
let mut builder = WalkBuilder::new(base_path); let mut builder = WalkBuilder::new(base_path);
builder.ignore(true).hidden(true); 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() { for result in builder.build() {
let absolute_candidate = result.unwrap(); let absolute_candidate = result.unwrap();

View file

@ -40,6 +40,13 @@ pub extern "C" fn ivy_init(c_base_dir: *const c_char) {
get_files(&directory); get_files(&directory);
} }
#[no_mangle]
pub extern "C" fn ivy_cwd() -> *const c_char {
return CString::new(std::env::current_dir().unwrap().to_str().unwrap())
.unwrap()
.into_raw();
}
#[no_mangle] #[no_mangle]
pub extern "C" fn ivy_match(c_pattern: *const c_char, c_text: *const c_char) -> c_int { pub extern "C" fn ivy_match(c_pattern: *const c_char, c_text: *const c_char) -> c_int {
let pattern = to_string(c_pattern); let pattern = to_string(c_pattern);