From 9e0a308ea62bbba6810a46e60676170bb9a51719 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Thu, 21 Mar 2024 09:01:36 +0000 Subject: [PATCH] fix(project): correctly ignore folders --- crates/biome_cli/src/execute/mod.rs | 19 +++++++++++++++---- crates/biome_cli/src/execute/traverse.rs | 2 +- crates/biome_service/src/workspace.rs | 2 +- crates/biome_service/src/workspace/server.rs | 14 +++++++++++--- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/crates/biome_cli/src/execute/mod.rs b/crates/biome_cli/src/execute/mod.rs index 16cccdeb67a0..166eb02f7556 100644 --- a/crates/biome_cli/src/execute/mod.rs +++ b/crates/biome_cli/src/execute/mod.rs @@ -10,7 +10,7 @@ use crate::execute::traverse::traverse; use crate::{CliDiagnostic, CliSession}; use biome_diagnostics::{category, Category}; use biome_fs::BiomePath; -use biome_service::workspace::{FeatureName, FixFileMode}; +use biome_service::workspace::{FeatureName, FeaturesBuilder, FixFileMode}; use std::ffi::OsString; use std::fmt::{Display, Formatter}; use std::path::{Path, PathBuf}; @@ -28,10 +28,21 @@ pub(crate) struct Execution { } impl Execution { - pub(crate) fn as_feature_name(&self) -> FeatureName { + pub(crate) fn to_features(&self) -> Vec { match self.traversal_mode { - TraversalMode::Format { .. } => FeatureName::Format, - _ => FeatureName::Lint, + TraversalMode::Format { .. } => FeaturesBuilder::new() + .with_formatter() + .build(), + TraversalMode::Lint { ..} => FeaturesBuilder::new() + .with_linter() + .build(), + TraversalMode::Check { .. } | TraversalMode::CI { .. } => FeaturesBuilder::new() + .with_organize_imports() + .with_formatter() + .with_linter() + .build(), + TraversalMode::Migrate { .. } => vec![] + } } } diff --git a/crates/biome_cli/src/execute/traverse.rs b/crates/biome_cli/src/execute/traverse.rs index 002207d08641..a58b3791e076 100644 --- a/crates/biome_cli/src/execute/traverse.rs +++ b/crates/biome_cli/src/execute/traverse.rs @@ -702,7 +702,7 @@ impl<'ctx, 'app> TraversalContext for TraversalOptions<'ctx, 'app> { .workspace .is_path_ignored(IsPathIgnoredParams { biome_path: biome_path.clone(), - feature: self.execution.as_feature_name(), + features: self.execution.to_features(), }) .unwrap_or_else(|err| { self.push_diagnostic(err.into()); diff --git a/crates/biome_service/src/workspace.rs b/crates/biome_service/src/workspace.rs index 7a30c7fde66e..d862d566e984 100644 --- a/crates/biome_service/src/workspace.rs +++ b/crates/biome_service/src/workspace.rs @@ -659,7 +659,7 @@ impl RageEntry { #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct IsPathIgnoredParams { pub biome_path: BiomePath, - pub feature: FeatureName, + pub features: Vec, } pub trait Workspace: Send + Sync + RefUnwindSafe { diff --git a/crates/biome_service/src/workspace/server.rs b/crates/biome_service/src/workspace/server.rs index 3a5d4f5347e9..690c26e90ce5 100644 --- a/crates/biome_service/src/workspace/server.rs +++ b/crates/biome_service/src/workspace/server.rs @@ -243,14 +243,22 @@ impl WorkspaceServer { /// Check whether a file is ignored in the top-level config `files.ignore`/`files.include` /// or in the feature `ignore`/`include` - fn is_ignored(&self, path: &Path, feature: FeatureName) -> bool { + fn is_ignored(&self, path: &Path, features: Vec) -> bool { let file_name = path.file_name().and_then(|s| s.to_str()); + let ignored_by_features = { + let mut ignored = false; + for feature in features { + // a path is ignored if it's ignored by all features + ignored &= self.is_ignored_by_feature_config(path, feature) + } + ignored + }; // Never ignore Biome's config file regardless `include`/`ignore` (file_name != Some(ConfigName::biome_json()) || file_name != Some(ConfigName::biome_jsonc())) && // Apply top-level `include`/`ignore` (self.is_ignored_by_top_level_config(path) || // Apply feature-level `include`/`ignore` - self.is_ignored_by_feature_config(path, feature)) + ignored_by_features) } /// Check whether a file is ignored in the top-level config `files.ignore`/`files.include` @@ -363,7 +371,7 @@ impl Workspace for WorkspaceServer { } } fn is_path_ignored(&self, params: IsPathIgnoredParams) -> Result { - Ok(self.is_ignored(params.biome_path.as_path(), params.feature)) + Ok(self.is_ignored(params.biome_path.as_path(), params.features)) } /// Update the global settings for this workspace ///