-
-
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
File picker config #988
File picker config #988
Changes from 13 commits
d686c8e
1f69124
e049182
07955f9
45c131c
339325f
69e9bc8
0740957
5fd9dca
4d1f0fa
8d8aa14
770e31e
c706744
5cfb86f
80ba0e0
5e07a6b
3b381df
92664a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1359,6 +1359,7 @@ fn global_search(cx: &mut Context) { | |||||||||||||||||||
let (all_matches_sx, all_matches_rx) = | ||||||||||||||||||||
tokio::sync::mpsc::unbounded_channel::<(usize, PathBuf)>(); | ||||||||||||||||||||
let smart_case = cx.editor.config.smart_case; | ||||||||||||||||||||
let file_picker_config = cx.editor.config.file_picker.clone(); | ||||||||||||||||||||
|
||||||||||||||||||||
let completions = search_completions(cx, None); | ||||||||||||||||||||
let prompt = ui::regex_prompt( | ||||||||||||||||||||
|
@@ -1387,41 +1388,55 @@ fn global_search(cx: &mut Context) { | |||||||||||||||||||
|
||||||||||||||||||||
let search_root = std::env::current_dir() | ||||||||||||||||||||
.expect("Global search error: Failed to get current dir"); | ||||||||||||||||||||
WalkBuilder::new(search_root).build_parallel().run(|| { | ||||||||||||||||||||
let mut searcher_cl = searcher.clone(); | ||||||||||||||||||||
let matcher_cl = matcher.clone(); | ||||||||||||||||||||
let all_matches_sx_cl = all_matches_sx.clone(); | ||||||||||||||||||||
Box::new(move |dent: Result<DirEntry, ignore::Error>| -> WalkState { | ||||||||||||||||||||
let dent = match dent { | ||||||||||||||||||||
Ok(dent) => dent, | ||||||||||||||||||||
Err(_) => return WalkState::Continue, | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
match dent.file_type() { | ||||||||||||||||||||
Some(fi) => { | ||||||||||||||||||||
if !fi.is_file() { | ||||||||||||||||||||
return WalkState::Continue; | ||||||||||||||||||||
WalkBuilder::new(search_root) | ||||||||||||||||||||
.hidden(file_picker_config.hidden) | ||||||||||||||||||||
.parents(file_picker_config.parents) | ||||||||||||||||||||
.ignore(file_picker_config.ignore) | ||||||||||||||||||||
.git_ignore(file_picker_config.git_ignore) | ||||||||||||||||||||
.git_global(file_picker_config.git_global) | ||||||||||||||||||||
.git_exclude(file_picker_config.git_exclude) | ||||||||||||||||||||
.max_depth(file_picker_config.max_depth) | ||||||||||||||||||||
.build_parallel() | ||||||||||||||||||||
.run(|| { | ||||||||||||||||||||
let mut searcher_cl = searcher.clone(); | ||||||||||||||||||||
let matcher_cl = matcher.clone(); | ||||||||||||||||||||
let all_matches_sx_cl = all_matches_sx.clone(); | ||||||||||||||||||||
Box::new(move |dent: Result<DirEntry, ignore::Error>| -> WalkState { | ||||||||||||||||||||
let dent = match dent { | ||||||||||||||||||||
Ok(dent) => dent, | ||||||||||||||||||||
Err(_) => return WalkState::Continue, | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
match dent.file_type() { | ||||||||||||||||||||
Some(fi) => { | ||||||||||||||||||||
if !fi.is_file() { | ||||||||||||||||||||
return WalkState::Continue; | ||||||||||||||||||||
} | ||||||||||||||||||||
} | ||||||||||||||||||||
None => return WalkState::Continue, | ||||||||||||||||||||
} | ||||||||||||||||||||
None => return WalkState::Continue, | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
let result_sink = sinks::UTF8(|line_num, _| { | ||||||||||||||||||||
match all_matches_sx_cl | ||||||||||||||||||||
.send((line_num as usize - 1, dent.path().to_path_buf())) | ||||||||||||||||||||
{ | ||||||||||||||||||||
Ok(_) => Ok(true), | ||||||||||||||||||||
Err(_) => Ok(false), | ||||||||||||||||||||
let result_sink = sinks::UTF8(|line_num, _| { | ||||||||||||||||||||
match all_matches_sx_cl | ||||||||||||||||||||
.send((line_num as usize - 1, dent.path().to_path_buf())) | ||||||||||||||||||||
{ | ||||||||||||||||||||
Ok(_) => Ok(true), | ||||||||||||||||||||
Err(_) => Ok(false), | ||||||||||||||||||||
} | ||||||||||||||||||||
Comment on lines
+1420
to
+1425
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This can probably be simplified, but probably needs reformatting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not believe I changed this logic in the course of this PR--the formatting changed due to the addition of the fluent-style calls above (lines 1392-1398). |
||||||||||||||||||||
}); | ||||||||||||||||||||
let result = | ||||||||||||||||||||
searcher_cl.search_path(&matcher_cl, dent.path(), result_sink); | ||||||||||||||||||||
|
||||||||||||||||||||
if let Err(err) = result { | ||||||||||||||||||||
log::error!( | ||||||||||||||||||||
"Global search error: {}, {}", | ||||||||||||||||||||
dent.path().display(), | ||||||||||||||||||||
err | ||||||||||||||||||||
); | ||||||||||||||||||||
} | ||||||||||||||||||||
}); | ||||||||||||||||||||
let result = searcher_cl.search_path(&matcher_cl, dent.path(), result_sink); | ||||||||||||||||||||
|
||||||||||||||||||||
if let Err(err) = result { | ||||||||||||||||||||
log::error!("Global search error: {}, {}", dent.path().display(), err); | ||||||||||||||||||||
} | ||||||||||||||||||||
WalkState::Continue | ||||||||||||||||||||
}) | ||||||||||||||||||||
}); | ||||||||||||||||||||
WalkState::Continue | ||||||||||||||||||||
}) | ||||||||||||||||||||
}); | ||||||||||||||||||||
} else { | ||||||||||||||||||||
// Otherwise do nothing | ||||||||||||||||||||
// log::warn!("Global Search Invalid Pattern") | ||||||||||||||||||||
|
@@ -2593,7 +2608,7 @@ fn command_mode(cx: &mut Context) { | |||||||||||||||||||
|
||||||||||||||||||||
fn file_picker(cx: &mut Context) { | ||||||||||||||||||||
let root = find_root(None).unwrap_or_else(|| PathBuf::from("./")); | ||||||||||||||||||||
let picker = ui::file_picker(root); | ||||||||||||||||||||
let picker = ui::file_picker(root, &cx.editor.config); | ||||||||||||||||||||
cx.push_layer(Box::new(picker)); | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,13 +93,22 @@ pub fn regex_prompt( | |
) | ||
} | ||
|
||
pub fn file_picker(root: PathBuf) -> FilePicker<PathBuf> { | ||
pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePicker<PathBuf> { | ||
use ignore::{types::TypesBuilder, WalkBuilder}; | ||
use std::time; | ||
|
||
// 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's another There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, thank you for review, I will look into this! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In commit 339325f I added a variable to allow for passing into The remaining changes were all due to formatting, using Helix with rust-analyser. |
||
walk_builder | ||
.hidden(config.file_picker.hidden) | ||
.parents(config.file_picker.parents) | ||
.ignore(config.file_picker.ignore) | ||
.git_ignore(config.file_picker.git_ignore) | ||
.git_global(config.file_picker.git_global) | ||
.git_exclude(config.file_picker.git_exclude) | ||
.max_depth(config.file_picker.max_depth); | ||
|
||
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}", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,42 @@ where | |
Ok(Duration::from_millis(millis)) | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Deserialize)] | ||
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)] | ||
pub struct FilePickerConfig { | ||
pub hidden: bool, | ||
pub parents: bool, | ||
pub ignore: bool, | ||
pub git_ignore: bool, | ||
pub git_global: bool, | ||
pub git_exclude: bool, | ||
pub max_depth: Option<usize>, | ||
} | ||
|
||
impl Default for FilePickerConfig { | ||
fn default() -> Self { | ||
Self { | ||
// IgnoreOptions | ||
// Enables ignoring hidden files. | ||
hidden: true, | ||
// Enables reading ignore files from parent directories. | ||
parents: true, | ||
// Enables reading `.ignore` files. | ||
ignore: true, | ||
// Enables reading `.gitignore` files. | ||
/// Whether to hide files in .gitignore from displaying in file picker. Defaults to false. | ||
git_ignore: true, | ||
// Enables reading global .gitignore, whose path is specified in git's config: `core.excludefile` option. | ||
git_global: true, | ||
// Enables reading `.git/info/exclude` files. | ||
git_exclude: true, | ||
// WalkBuilder options | ||
// Maximum Depth to recurse. | ||
max_depth: None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These comments should really be doc comments ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I saw that was the way with previous config, now that makes sense. I'll make an adjustment. |
||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Deserialize)] | ||
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)] | ||
pub struct Config { | ||
|
@@ -61,6 +97,9 @@ pub struct Config { | |
pub completion_trigger_len: u8, | ||
/// Whether to display infoboxes. Defaults to true. | ||
pub auto_info: bool, | ||
/// Whether to hide files in .gitignore from displaying in file picker. Defaults to false. | ||
//pub git_ignore: bool, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very good. |
||
pub file_picker: FilePickerConfig, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)] | ||
|
@@ -92,6 +131,7 @@ impl Default for Config { | |
idle_timeout: Duration::from_millis(400), | ||
completion_trigger_len: 2, | ||
auto_info: true, | ||
file_picker: FilePickerConfig::default(), | ||
} | ||
} | ||
} | ||
|
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.
I think it would be better to move this to an "
[editor.file-picker]
section" like the "[editor]
section" above and have the same key, description, default table.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.
Okay, I will make a commit for this today. Thank you!
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.
I think that the commit 80ba0e0 has the changes you were looking for!