Conside include, extend-include for the native server (#12252)

## Summary

This PR updates the native server to consider the `include` and
`extend-include` file resolver settings.

fixes: #12242 

## Test Plan

Note: Settings reloading doesn't work for nested configs which is fixed
in #12253 so the preview here only showcases root level config.

e8969128-c175-4f98-8114-0d692b906cc8
This commit is contained in:
Dhruv Manilawala 2024-07-10 09:42:57 +05:30 committed by GitHub
parent 855d62cdde
commit 0bb2fc6eec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 101 additions and 47 deletions

View file

@ -683,6 +683,39 @@ pub fn match_any_exclusion(
None
}
#[derive(Debug, Copy, Clone)]
pub enum InclusionKind {
/// The inclusion came from the `include` setting.
Include,
/// The inclusion came from the `extend-include` setting.
ExtendInclude,
}
impl std::fmt::Display for InclusionKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
InclusionKind::Include => write!(f, "include"),
InclusionKind::ExtendInclude => write!(f, "extend-include"),
}
}
}
/// Return the [`InclusionKind`] for a given [`Path`], if the path match any of the inclusion
/// criteria.
pub fn match_any_inclusion(
path: &Path,
include: &GlobSet,
extend_include: &GlobSet,
) -> Option<InclusionKind> {
if include.is_match(path) {
Some(InclusionKind::Include)
} else if extend_include.is_match(path) {
Some(InclusionKind::ExtendInclude)
} else {
None
}
}
#[cfg(test)]
mod tests {
use std::fs::{create_dir, File};