Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions crates/biome_service/src/projects.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::is_dir;
use crate::settings::{FilesSettings, Settings, VcsIgnoredPatterns};
use crate::settings::Settings;
use crate::workspace::FeatureKind;
use camino::{Utf8Path, Utf8PathBuf};
use papaya::HashMap;
Expand Down Expand Up @@ -126,24 +126,36 @@ impl Projects {
.map(|data| data.root_settings.clone())
}

/// Retrieves the `files` settings for the given project.
pub fn get_files_settings(
&self,
project_key: ProjectKey,
path: &Utf8Path,
) -> Option<FilesSettings> {
self.get_settings_based_on_path(project_key, path)
.map(|settings| settings.files.clone())
pub fn is_ignored_by_scanner(&self, project_key: ProjectKey, path: &Utf8Path) -> bool {
self.0.pin().get(&project_key).is_none_or(|data| {
let ignore_entries = &data.root_settings.files.scanner_ignore_entries;
path.components().any(|component| {
ignore_entries
.iter()
.any(|entry| entry == component.as_os_str().as_encoded_bytes())
})
})
}

/// Retrieves the ignore matches that have been stored inside the settings of the current project
pub fn get_vcs_ignored_matches(
&self,
project_key: ProjectKey,
path: &Utf8Path,
) -> Option<VcsIgnoredPatterns> {
pub fn is_ignored_by_top_level_config(&self, project_key: ProjectKey, path: &Utf8Path) -> bool {
self.get_settings_based_on_path(project_key, path)
.and_then(|settings| settings.vcs_settings.ignore_matches.clone())
.is_some_and(|settings| {
let includes = &settings.files.includes;

let mut is_included = true;
if !includes.is_unset() {
is_included = if is_dir(path) {
includes.matches_directory_with_exceptions(path)
} else {
includes.matches_with_exceptions(path)
};
}

!is_included
|| settings.vcs_settings.ignore_matches.as_ref().is_some_and(
|ignored_matches| ignored_matches.is_ignored(path, is_dir(path)),
)
})
}

/// Sets the root settings for the given project.
Expand Down
6 changes: 5 additions & 1 deletion crates/biome_service/src/workspace/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,11 @@ impl TraversalContext for ScanContext<'_> {
// We roughly understand which files should be open by the scanner.
// Here, we mostly do file operations by reading their metadata.
fn can_handle(&self, path: &BiomePath) -> bool {
if self.workspace.is_ignored_by_scanner(self.project_key, path) {
if self
.workspace
.projects
.is_ignored_by_scanner(self.project_key, path)
{
return false;
}

Expand Down
36 changes: 4 additions & 32 deletions crates/biome_service/src/workspace/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::workspace::{
ServerInfo,
};
use crate::workspace_watcher::{OpenFileReason, WatcherSignalKind};
use crate::{WatcherInstruction, Workspace, WorkspaceError, is_dir};
use crate::{WatcherInstruction, Workspace, WorkspaceError};
use append_only_vec::AppendOnlyVec;
use biome_analyze::{AnalyzerPluginVec, RuleCategory};
use biome_configuration::analyzer::RuleSelector;
Expand Down Expand Up @@ -552,40 +552,12 @@ impl WorkspaceServer {

/// Checks whether a file is ignored in the top-level `files.includes`.
fn is_ignored_by_top_level_config(&self, project_key: ProjectKey, path: &Utf8Path) -> bool {
let Some(files_settings) = self.projects.get_files_settings(project_key, path) else {
return false;
};
let mut is_included = true;
if !files_settings.includes.is_unset() {
is_included = if is_dir(path) {
files_settings
.includes
.matches_directory_with_exceptions(path)
} else {
files_settings.includes.matches_with_exceptions(path)
};
}

let ignore_matches = self.projects.get_vcs_ignored_matches(project_key, path);

!is_included
|| ignore_matches
.as_ref()
.is_some_and(|ignored_matches| ignored_matches.is_ignored(path, is_dir(path)))
self.projects
.is_ignored_by_top_level_config(project_key, path)
}

pub(super) fn is_ignored_by_scanner(&self, project_key: ProjectKey, path: &Utf8Path) -> bool {
let Some(settings) = self.projects.get_root_settings(project_key) else {
return true; // If the project isn't loaded, nothing should be scanned.
};

path.components().any(|component| {
settings
.files
.scanner_ignore_entries
.iter()
.any(|entry| entry == component.as_os_str().as_encoded_bytes())
})
self.projects.is_ignored_by_scanner(project_key, path)
}

fn load_plugins(&self, base_path: &Utf8Path, plugins: &Plugins) -> Vec<PluginDiagnostic> {
Expand Down