Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: expose ProjectLayout as service #4851

Merged
merged 8 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
refactor: expose ProjectLayout as service
  • Loading branch information
arendjr committed Jan 7, 2025
commit 76a491c63638bb849c1b3f587a1f67d571748357
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ biome_markdown_factory = { version = "0.0.1", path = "./crates/biome_markd
biome_markdown_parser = { version = "0.0.1", path = "./crates/biome_markdown_parser" }
biome_markdown_syntax = { version = "0.0.1", path = "./crates/biome_markdown_syntax" }
biome_plugin_loader = { version = "0.0.1", path = "./crates/biome_plugin_loader" }
biome_project_layout = { version = "0.0.1", path = "./crates/biome_project_layout" }
biome_ungrammar = { version = "0.3.1", path = "./crates/biome_ungrammar" }
biome_yaml_factory = { version = "0.0.1", path = "./crates/biome_yaml_factory" }
biome_yaml_parser = { version = "0.0.1", path = "./crates/biome_yaml_parser" }
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_analyze/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ biome_diagnostics = { workspace = true }
biome_parser = { workspace = true }
biome_rowan = { workspace = true }
biome_suppression = { workspace = true }
camino = { workspace = true }
enumflags2 = { workspace = true }
indexmap = { workspace = true }
rustc-hash = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"], optional = true }
tracing = { workspace = true }


[features]
schema = ["dep:schemars", "biome_console/schema", "serde"]
serde = ["dep:serde", "dep:biome_deserialize", "dep:biome_deserialize_macros"]
Expand Down
5 changes: 3 additions & 2 deletions crates/biome_analyze/src/analyzer_plugin.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::RuleDiagnostic;
use biome_parser::AnyParse;
use std::{fmt::Debug, path::PathBuf};
use camino::Utf8PathBuf;
use std::fmt::Debug;

/// Definition of an analyzer plugin.
pub trait AnalyzerPlugin: Debug {
fn evaluate(&self, root: AnyParse, path: PathBuf) -> Vec<RuleDiagnostic>;
fn evaluate(&self, root: AnyParse, path: Utf8PathBuf) -> Vec<RuleDiagnostic>;

fn supports_css(&self) -> bool;

Expand Down
10 changes: 5 additions & 5 deletions crates/biome_analyze/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::options::{JsxRuntime, PreferredQuote};
use crate::{registry::RuleRoot, FromServices, Queryable, Rule, RuleKey, ServiceBag};
use crate::{GroupCategory, RuleCategory, RuleGroup, RuleMetadata};
use biome_diagnostics::{Error, Result};
use camino::Utf8Path;
use std::ops::Deref;
use std::path::Path;

type RuleQueryResult<R> = <<R as Rule>::Query as Queryable>::Output;
type RuleServiceBag<R> = <<R as Rule>::Query as Queryable>::Services;
Expand All @@ -14,7 +14,7 @@ pub struct RuleContext<'a, R: Rule> {
bag: &'a ServiceBag,
services: RuleServiceBag<R>,
globals: &'a [&'a str],
file_path: &'a Path,
file_path: &'a Utf8Path,
options: &'a R::Options,
preferred_quote: &'a PreferredQuote,
jsx_runtime: Option<JsxRuntime>,
Expand All @@ -30,7 +30,7 @@ where
root: &'a RuleRoot<R>,
services: &'a ServiceBag,
globals: &'a [&'a str],
file_path: &'a Path,
file_path: &'a Utf8Path,
options: &'a R::Options,
preferred_quote: &'a PreferredQuote,
jsx_runtime: Option<JsxRuntime>,
Expand All @@ -40,7 +40,7 @@ where
query_result,
root,
bag: services,
services: FromServices::from_services(&rule_key, services)?,
services: FromServices::from_services(&rule_key, services, file_path)?,
globals,
file_path,
options,
Expand Down Expand Up @@ -159,7 +159,7 @@ where
}

/// The file path of the current file
pub fn file_path(&self) -> &Path {
pub fn file_path(&self) -> &Utf8Path {
self.file_path
}

Expand Down
6 changes: 3 additions & 3 deletions crates/biome_analyze/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use camino::Utf8PathBuf;
use rustc_hash::FxHashMap;

use crate::{FixKind, Rule, RuleKey};
use std::any::{Any, TypeId};
use std::fmt::Debug;
use std::path::PathBuf;

/// A convenient new type data structure to store the options that belong to a rule
#[derive(Debug)]
Expand Down Expand Up @@ -98,14 +98,14 @@ pub struct AnalyzerOptions {
pub(crate) configuration: AnalyzerConfiguration,

/// The file that is being analyzed
pub(crate) file_path: PathBuf,
pub(crate) file_path: Utf8PathBuf,

/// Suppression reason used when applying a suppression code action
pub(crate) suppression_reason: Option<String>,
}

impl AnalyzerOptions {
pub fn with_file_path(mut self, file_path: impl Into<PathBuf>) -> Self {
pub fn with_file_path(mut self, file_path: impl Into<Utf8PathBuf>) -> Self {
self.file_path = file_path.into();
self
}
Expand Down
8 changes: 7 additions & 1 deletion crates/biome_analyze/src/services.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{RuleKey, TextRange};
use biome_diagnostics::{Diagnostic, LineIndexBuf, Resource, Result, SourceCode};
use camino::Utf8Path;
use rustc_hash::FxHashMap;
use std::any::{Any, TypeId};

Expand Down Expand Up @@ -36,6 +37,7 @@ pub trait FromServices: Sized {
fn from_services(
rule_key: &RuleKey,
services: &ServiceBag,
file_path: &Utf8Path,
) -> Result<Self, MissingServicesDiagnostic>;
}

Expand All @@ -58,7 +60,11 @@ impl ServiceBag {
}

impl FromServices for () {
fn from_services(_: &RuleKey, _: &ServiceBag) -> Result<Self, MissingServicesDiagnostic> {
fn from_services(
_: &RuleKey,
_: &ServiceBag,
_: &Utf8Path,
) -> Result<Self, MissingServicesDiagnostic> {
Ok(())
}
}
1 change: 1 addition & 0 deletions crates/biome_css_analyze/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ biome_diagnostics = { workspace = true }
biome_rowan = { workspace = true }
biome_string_case = { workspace = true }
biome_suppression = { workspace = true }
camino = { workspace = true }
regex = { workspace = true }
rustc-hash = { workspace = true }
schemars = { workspace = true, optional = true }
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_css_analyze/src/services/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use biome_css_semantic::builder::SemanticModelBuilder;
use biome_css_semantic::{model::SemanticModel, SemanticEventExtractor};
use biome_css_syntax::{CssLanguage, CssRoot, CssSyntaxNode};
use biome_rowan::{AstNode, TextRange, WalkEvent};
use camino::Utf8Path;

/// The [SemanticServices] types can be used as a queryable to get an instance
/// of the whole [SemanticModel] without matching on a specific AST node
Expand Down Expand Up @@ -40,6 +41,7 @@ impl FromServices for SemanticServices {
fn from_services(
rule_key: &RuleKey,
services: &ServiceBag,
_file_path: &Utf8Path,
) -> Result<Self, MissingServicesDiagnostic> {
let model: &SemanticModel = services.get_service().ok_or_else(|| {
MissingServicesDiagnostic::new(rule_key.rule_name(), &["SemanticModel"])
Expand Down
7 changes: 2 additions & 5 deletions crates/biome_grit_patterns/src/grit_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ fn new_file_owner(
/// that can use the Biome workspace.
#[derive(Clone, Debug)]
pub struct GritTargetFile {
pub path: PathBuf,
pub path: Utf8PathBuf,
pub parse: AnyParse,
}

Expand All @@ -323,9 +323,6 @@ impl GritTargetFile {
let parser = target_language.get_parser();
let parse = parser.parse_with_path(source, &path);

Self {
parse,
path: path.into(),
}
Self { parse, path }
}
}
8 changes: 6 additions & 2 deletions crates/biome_grit_patterns/src/grit_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ impl GritQuery {

let var_registry = VarRegistry::from_locations(&self.variable_locations);

let file_registry =
FileRegistry::new_from_paths(files.iter().map(|file| &file.path).collect());
// FIXME: Can be simplified when https://github.com/getgrit/gritql/pull/594/files is released.
let paths: Vec<PathBuf> = files
.iter()
.map(|file| file.path.clone().into_std_path_buf())
.collect();
let file_registry = FileRegistry::new_from_paths(paths.iter().collect());
let binding = FilePattern::Single(file_ptr);

let mut state = State::new(var_registry.into(), file_registry);
Expand Down
1 change: 1 addition & 0 deletions crates/biome_js_analyze/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ biome_js_factory = { workspace = true }
biome_js_semantic = { workspace = true }
biome_js_syntax = { workspace = true }
biome_package = { workspace = true }
biome_project_layout = { workspace = true }
biome_rowan = { workspace = true }
biome_string_case = { workspace = true }
biome_suppression = { workspace = true }
Expand Down
Loading
Loading