Refactor path ignore rule handling in Project and ServeSession

- Introduced a new method `path_ignore_rules` in the Project struct to streamline the creation of PathIgnoreRule instances.
- Updated ServeSession and snapshot middleware to utilize the new method, improving code clarity and reducing duplication.
- Removed redundant PathIgnoreRule mapping from multiple locations, enhancing maintainability.
This commit is contained in:
Joe 2026-03-06 23:12:28 -06:00
parent 89869f685d
commit 0243181731
3 changed files with 21 additions and 23 deletions

View file

@ -12,7 +12,11 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;
use crate::{
glob::Glob, json, resolution::UnresolvedValue, snapshot::SyncRule, syncback::SyncbackRules,
glob::Glob,
json,
resolution::UnresolvedValue,
snapshot::{PathIgnoreRule, SyncRule},
syncback::SyncbackRules,
};
/// Represents 'default' project names that act as `init` files
@ -334,6 +338,17 @@ impl Project {
pub fn folder_location(&self) -> &Path {
self.file_location.parent().unwrap()
}
pub fn path_ignore_rules(&self) -> Vec<PathIgnoreRule> {
let base = self.folder_location().to_path_buf();
self.glob_ignore_paths
.iter()
.map(|glob| PathIgnoreRule {
glob: glob.clone(),
base_path: base.clone(),
})
.collect()
}
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]

View file

@ -17,7 +17,7 @@ use crate::{
session_id::SessionId,
snapshot::{
apply_patch_set, compute_patch_set, AppliedPatchSet, InstanceContext, InstanceSnapshot,
PatchSet, PathIgnoreRule, RojoTree,
PatchSet, RojoTree,
},
snapshot_middleware::{is_script_relevant_path, snapshot_from_vfs, INIT_FILE_PRIORITY},
};
@ -138,14 +138,7 @@ fn prefetch_project_files(project: &Project, sync_scripts_only: bool) -> io::Res
let folder = project.folder_location();
let ignore_rules: Vec<PathIgnoreRule> = project
.glob_ignore_paths
.iter()
.map(|glob| PathIgnoreRule {
glob: glob.clone(),
base_path: folder.to_path_buf(),
})
.collect();
let ignore_rules = project.path_ignore_rules();
let mut roots: Vec<std::path::PathBuf> = Vec::new();
collect_path_roots(&project.tree, folder, &mut roots);
@ -454,14 +447,7 @@ impl ServeSession {
.as_deref()
.and_then(crate::git::git_head_commit);
let path_ignore_rules: Vec<PathIgnoreRule> = root_project
.glob_ignore_paths
.iter()
.map(|glob| PathIgnoreRule {
glob: glob.clone(),
base_path: root_project.folder_location().to_path_buf(),
})
.collect();
let path_ignore_rules = root_project.path_ignore_rules();
log::trace!("Starting ChangeProcessor");
let change_processor = ChangeProcessor::start(

View file

@ -17,7 +17,7 @@ use crate::{
resolution::UnresolvedValue,
snapshot::{
InstanceContext, InstanceMetadata, InstanceSnapshot, InstanceWithMeta, InstigatingSource,
PathIgnoreRule, SyncRule,
SyncRule,
},
snapshot_middleware::Middleware,
syncback::{
@ -115,10 +115,7 @@ pub fn snapshot_project(
let mut context = context.clone();
context.clear_sync_rules();
let rules = project.glob_ignore_paths.iter().map(|glob| PathIgnoreRule {
glob: glob.clone(),
base_path: project.folder_location().to_path_buf(),
});
let rules = project.path_ignore_rules();
let sync_rules = project.sync_rules.iter().map(|rule| SyncRule {
base_path: project.folder_location().to_path_buf(),