Add file_scan_inclusions
setting to customize Zed file indexing (#16852)
Closes #4745 Release Notes: - Added a new `file_scan_inclusions` setting to force Zed to index files that match the provided globs, even if they're gitignored. --------- Co-authored-by: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
parent
95ace03706
commit
0e62b6dddd
6 changed files with 350 additions and 25 deletions
|
@ -9,6 +9,7 @@ use util::paths::PathMatcher;
|
|||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct WorktreeSettings {
|
||||
pub file_scan_inclusions: PathMatcher,
|
||||
pub file_scan_exclusions: PathMatcher,
|
||||
pub private_files: PathMatcher,
|
||||
}
|
||||
|
@ -21,13 +22,19 @@ impl WorktreeSettings {
|
|||
|
||||
pub fn is_path_excluded(&self, path: &Path) -> bool {
|
||||
path.ancestors()
|
||||
.any(|ancestor| self.file_scan_exclusions.is_match(ancestor))
|
||||
.any(|ancestor| self.file_scan_exclusions.is_match(&ancestor))
|
||||
}
|
||||
|
||||
pub fn is_path_always_included(&self, path: &Path) -> bool {
|
||||
path.ancestors()
|
||||
.any(|ancestor| self.file_scan_inclusions.is_match(&ancestor))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct WorktreeSettingsContent {
|
||||
/// Completely ignore files matching globs from `file_scan_exclusions`
|
||||
/// Completely ignore files matching globs from `file_scan_exclusions`. Overrides
|
||||
/// `file_scan_inclusions`.
|
||||
///
|
||||
/// Default: [
|
||||
/// "**/.git",
|
||||
|
@ -42,6 +49,15 @@ pub struct WorktreeSettingsContent {
|
|||
#[serde(default)]
|
||||
pub file_scan_exclusions: Option<Vec<String>>,
|
||||
|
||||
/// Always include files that match these globs when scanning for files, even if they're
|
||||
/// ignored by git. This setting is overridden by `file_scan_exclusions`.
|
||||
/// Default: [
|
||||
/// ".env*",
|
||||
/// "docker-compose.*.yml",
|
||||
/// ]
|
||||
#[serde(default)]
|
||||
pub file_scan_inclusions: Option<Vec<String>>,
|
||||
|
||||
/// Treat the files matching these globs as `.env` files.
|
||||
/// Default: [ "**/.env*" ]
|
||||
pub private_files: Option<Vec<String>>,
|
||||
|
@ -59,11 +75,27 @@ impl Settings for WorktreeSettings {
|
|||
let result: WorktreeSettingsContent = sources.json_merge()?;
|
||||
let mut file_scan_exclusions = result.file_scan_exclusions.unwrap_or_default();
|
||||
let mut private_files = result.private_files.unwrap_or_default();
|
||||
let mut parsed_file_scan_inclusions: Vec<String> = result
|
||||
.file_scan_inclusions
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.flat_map(|glob| {
|
||||
Path::new(glob)
|
||||
.ancestors()
|
||||
.map(|a| a.to_string_lossy().into())
|
||||
})
|
||||
.filter(|p| p != "")
|
||||
.collect();
|
||||
file_scan_exclusions.sort();
|
||||
private_files.sort();
|
||||
parsed_file_scan_inclusions.sort();
|
||||
Ok(Self {
|
||||
file_scan_exclusions: path_matchers(&file_scan_exclusions, "file_scan_exclusions")?,
|
||||
private_files: path_matchers(&private_files, "private_files")?,
|
||||
file_scan_inclusions: path_matchers(
|
||||
&parsed_file_scan_inclusions,
|
||||
"file_scan_inclusions",
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue