Skip to content

Commit 7264e15

Browse files
PaulOlteanumtoohey31
authored andcommitted
Add helix-specific ignore files (helix-editor#8099)
1 parent 09f5929 commit 7264e15

2 files changed

Lines changed: 75 additions & 65 deletions

File tree

helix-term/src/commands.rs

Lines changed: 72 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,10 @@ fn global_search(cx: &mut Context) {
21842184
let searcher = SearcherBuilder::new()
21852185
.binary_detection(BinaryDetection::quit(b'\x00'))
21862186
.build();
2187-
WalkBuilder::new(search_root)
2187+
2188+
let mut walk_builder = WalkBuilder::new(search_root);
2189+
2190+
walk_builder
21882191
.hidden(file_picker_config.hidden)
21892192
.parents(file_picker_config.parents)
21902193
.ignore(file_picker_config.ignore)
@@ -2195,73 +2198,77 @@ fn global_search(cx: &mut Context) {
21952198
.max_depth(file_picker_config.max_depth)
21962199
.filter_entry(move |entry| {
21972200
filter_picker_entry(entry, &absolute_root, dedup_symlinks)
2198-
})
2199-
.build_parallel()
2200-
.run(|| {
2201-
let mut searcher = searcher.clone();
2202-
let matcher = matcher.clone();
2203-
let injector = injector_.clone();
2204-
let documents = &documents;
2205-
Box::new(move |entry: Result<DirEntry, ignore::Error>| -> WalkState {
2206-
let entry = match entry {
2207-
Ok(entry) => entry,
2208-
Err(_) => return WalkState::Continue,
2209-
};
2210-
2211-
match entry.file_type() {
2212-
Some(entry) if entry.is_file() => {}
2213-
// skip everything else
2214-
_ => return WalkState::Continue,
2215-
};
2216-
2217-
let mut stop = false;
2218-
let sink = sinks::UTF8(|line_num, _| {
2219-
stop = injector
2220-
.push(FileResult::new(entry.path(), line_num as usize - 1))
2221-
.is_err();
2222-
2223-
Ok(!stop)
2224-
});
2225-
let doc = documents.iter().find(|&(doc_path, _)| {
2226-
doc_path
2227-
.as_ref()
2228-
.map_or(false, |doc_path| doc_path == entry.path())
2229-
});
2230-
2231-
let result = if let Some((_, doc)) = doc {
2232-
// there is already a buffer for this file
2233-
// search the buffer instead of the file because it's faster
2234-
// and captures new edits without requiring a save
2235-
if searcher.multi_line_with_matcher(&matcher) {
2236-
// in this case a continous buffer is required
2237-
// convert the rope to a string
2238-
let text = doc.to_string();
2239-
searcher.search_slice(&matcher, text.as_bytes(), sink)
2240-
} else {
2241-
searcher.search_reader(
2242-
&matcher,
2243-
RopeReader::new(doc.slice(..)),
2244-
sink,
2245-
)
2246-
}
2247-
} else {
2248-
searcher.search_path(&matcher, entry.path(), sink)
2249-
};
2201+
});
22502202

2251-
if let Err(err) = result {
2252-
log::error!(
2253-
"Global search error: {}, {}",
2254-
entry.path().display(),
2255-
err
2256-
);
2257-
}
2258-
if stop {
2259-
WalkState::Quit
2203+
walk_builder
2204+
.add_custom_ignore_filename(helix_loader::config_dir().join("ignore"));
2205+
walk_builder.add_custom_ignore_filename(".helix/ignore");
2206+
2207+
walk_builder.build_parallel().run(|| {
2208+
let mut searcher = searcher.clone();
2209+
let matcher = matcher.clone();
2210+
let injector = injector_.clone();
2211+
let documents = &documents;
2212+
Box::new(move |entry: Result<DirEntry, ignore::Error>| -> WalkState {
2213+
let entry = match entry {
2214+
Ok(entry) => entry,
2215+
Err(_) => return WalkState::Continue,
2216+
};
2217+
2218+
match entry.file_type() {
2219+
Some(entry) if entry.is_file() => {}
2220+
// skip everything else
2221+
_ => return WalkState::Continue,
2222+
};
2223+
2224+
let mut stop = false;
2225+
let sink = sinks::UTF8(|line_num, _| {
2226+
stop = injector
2227+
.push(FileResult::new(entry.path(), line_num as usize - 1))
2228+
.is_err();
2229+
2230+
Ok(!stop)
2231+
});
2232+
let doc = documents.iter().find(|&(doc_path, _)| {
2233+
doc_path
2234+
.as_ref()
2235+
.map_or(false, |doc_path| doc_path == entry.path())
2236+
});
2237+
2238+
let result = if let Some((_, doc)) = doc {
2239+
// there is already a buffer for this file
2240+
// search the buffer instead of the file because it's faster
2241+
// and captures new edits without requiring a save
2242+
if searcher.multi_line_with_matcher(&matcher) {
2243+
// in this case a continous buffer is required
2244+
// convert the rope to a string
2245+
let text = doc.to_string();
2246+
searcher.search_slice(&matcher, text.as_bytes(), sink)
22602247
} else {
2261-
WalkState::Continue
2248+
searcher.search_reader(
2249+
&matcher,
2250+
RopeReader::new(doc.slice(..)),
2251+
sink,
2252+
)
22622253
}
2263-
})
2264-
});
2254+
} else {
2255+
searcher.search_path(&matcher, entry.path(), sink)
2256+
};
2257+
2258+
if let Err(err) = result {
2259+
log::error!(
2260+
"Global search error: {}, {}",
2261+
entry.path().display(),
2262+
err
2263+
);
2264+
}
2265+
if stop {
2266+
WalkState::Quit
2267+
} else {
2268+
WalkState::Continue
2269+
}
2270+
})
2271+
});
22652272
});
22662273

22672274
cx.jobs.callback(async move {

helix-term/src/ui/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> Picker
177177
.max_depth(config.file_picker.max_depth)
178178
.filter_entry(move |entry| filter_picker_entry(entry, &absolute_root, dedup_symlinks));
179179

180+
walk_builder.add_custom_ignore_filename(helix_loader::config_dir().join("ignore"));
181+
walk_builder.add_custom_ignore_filename(".helix/ignore");
182+
180183
// We want to exclude files that the editor can't handle yet
181184
let mut type_builder = TypesBuilder::new();
182185
type_builder

0 commit comments

Comments
 (0)