Skip to content

Commit

Permalink
feat: add biome_project (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Nov 2, 2023
1 parent a3ef0ef commit 1f5e239
Show file tree
Hide file tree
Showing 50 changed files with 1,296 additions and 101 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ biome-cli-dev = "run -p biome_cli --"
codegen = "run -p xtask_codegen --"
codegen-bindings = "run -p xtask_codegen --features schema -- bindings"
codegen-configuration = "run -p xtask_codegen --features configuration -- configuration"
codegen-license = "run -p xtask_codegen --features license -- license"
codegen-schema = "run -p xtask_codegen --features schema -- schema"
codegen-website = "run -p xtask_codegen --features website -- website"
contributors = "run -p xtask_contributors --"
Expand Down
99 changes: 99 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 @@ -66,6 +66,7 @@ biome_flags = { path = "./crates/biome_flags" }
biome_formatter_test = { path = "./crates/biome_formatter_test" }
biome_lsp = { path = "./crates/biome_lsp" }
biome_migrate = { path = "./crates/biome_migrate" }
biome_project = { path = "./crates/biome_project" }
biome_service = { path = "./crates/biome_service" }
biome_test_utils = { path = "./crates/biome_test_utils" }
tests_macros = { path = "./crates/tests_macros" }
Expand Down
9 changes: 3 additions & 6 deletions crates/biome_cli/src/execute/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ pub(crate) fn run(
let mut tree = parsed.tree();
let mut actions = Vec::new();
loop {
let (action, _) = migrate_configuration(
&tree.value().unwrap(),
configuration_file_path.as_path(),
|signal| {
let (action, _) =
migrate_configuration(&tree, configuration_file_path.as_path(), |signal| {
let current_diagnostic = signal.diagnostic();
if current_diagnostic.is_some() {
errors += 1;
Expand All @@ -53,8 +51,7 @@ pub(crate) fn run(
}

ControlFlow::Continue(())
},
);
});

match action {
Some(action) => {
Expand Down
10 changes: 5 additions & 5 deletions crates/biome_cli/src/execute/process_file/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(crate) fn lint_with_guard<'ctx>(
let mut input = workspace_file.input()?;

if let Some(fix_mode) = ctx.execution.as_fix_file_mode() {
let fixed = workspace_file
let fix_result = workspace_file
.guard()
.fix_file(*fix_mode, false)
.with_file_path_and_code(
Expand All @@ -32,14 +32,14 @@ pub(crate) fn lint_with_guard<'ctx>(
)?;

ctx.push_message(Message::SkippedFixes {
skipped_suggested_fixes: fixed.skipped_suggested_fixes,
skipped_suggested_fixes: fix_result.skipped_suggested_fixes,
});

if fixed.code != input {
workspace_file.update_file(fixed.code)?;
if fix_result.code != input {
workspace_file.update_file(fix_result.code)?;
input = workspace_file.input()?;
}
errors = fixed.errors;
errors = fix_result.errors;
}

let max_diagnostics = ctx.remaining_diagnostics.load(Ordering::Relaxed);
Expand Down
20 changes: 18 additions & 2 deletions crates/biome_deserialize/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ use indexmap::IndexSet;
use std::num::ParseIntError;

/// Main trait to
///
pub trait JsonDeserialize: Sized {
/// It accepts a JSON AST and a visitor. The visitor is the [default](Default) implementation of the data
/// type that implements this trait.
fn deserialize_from_ast(
root: &JsonRoot,
visitor: &mut impl VisitJsonNode,
diagnostics: &mut Vec<DeserializationDiagnostic>,
deserialize_diagnostics: &mut Vec<DeserializationDiagnostic>,
) -> Option<()>;
}

impl JsonDeserialize for () {
fn deserialize_from_ast(
_root: &JsonRoot,
_visitor: &mut impl VisitJsonNode,
_diagnostics: &mut Vec<DeserializationDiagnostic>,
_deserialize_diagnostics: &mut Vec<DeserializationDiagnostic>,
) -> Option<()> {
Some(())
}
Expand Down Expand Up @@ -566,6 +567,7 @@ where
let mut output = Output::default();
let mut diagnostics = vec![];
let parse = parse_json(source, options);

Output::deserialize_from_ast(&parse.tree(), &mut output, &mut diagnostics);
let mut errors = parse
.into_diagnostics()
Expand Down Expand Up @@ -597,3 +599,17 @@ where
deserialized: output,
}
}

/// Attempts to deserialize a JSON AST, given the `Output`.
pub fn deserialize_from_json_root<Output>(parse: &JsonRoot) -> Deserialized<Output>
where
Output: Default + VisitJsonNode + JsonDeserialize,
{
let mut output = Output::default();
let mut diagnostics = vec![];
Output::deserialize_from_ast(parse, &mut output, &mut diagnostics);
Deserialized {
diagnostics: diagnostics.into_iter().map(Error::from).collect::<Vec<_>>(),
deserialized: output,
}
}
1 change: 1 addition & 0 deletions crates/biome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ define_categories! {
"organizeImports",
"migrate",
"deserialize",
"project",
"internalError/io",
"internalError/fs",
"internalError/panic",
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_json_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ mod tests {
let rule_filter = RuleFilter::Rule("nursery", "noDuplicateKeys");
let options = AnalyzerOptions::default();
analyze(
&parsed.tree().value().unwrap(),
&parsed.tree(),
AnalysisFilter {
enabled_rules: Some(slice::from_ref(&rule_filter)),
..AnalysisFilter::default()
Expand Down
35 changes: 17 additions & 18 deletions crates/biome_json_analyze/tests/spec_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,29 @@ pub(crate) fn analyze_and_snap(
let mut code_fixes = Vec::new();
let options = create_analyzer_options(input_file, &mut diagnostics);

let (_, errors) =
biome_json_analyze::analyze(&root.value().unwrap(), filter, &options, |event| {
if let Some(mut diag) = event.diagnostic() {
for action in event.actions() {
if !action.is_suppression() {
check_code_action(input_file, input_code, &action);
diag = diag.add_code_suggestion(CodeSuggestionAdvice::from(action));
}
}

let error = diag.with_severity(Severity::Warning);
diagnostics.push(diagnostic_to_string(file_name, input_code, error));
return ControlFlow::Continue(());
}

let (_, errors) = biome_json_analyze::analyze(&root, filter, &options, |event| {
if let Some(mut diag) = event.diagnostic() {
for action in event.actions() {
if !action.is_suppression() {
check_code_action(input_file, input_code, &action);
code_fixes.push(code_fix_to_string(input_code, action));
diag = diag.add_code_suggestion(CodeSuggestionAdvice::from(action));
}
}

ControlFlow::<Never>::Continue(())
});
let error = diag.with_severity(Severity::Warning);
diagnostics.push(diagnostic_to_string(file_name, input_code, error));
return ControlFlow::Continue(());
}

for action in event.actions() {
if !action.is_suppression() {
check_code_action(input_file, input_code, &action);
code_fixes.push(code_fix_to_string(input_code, action));
}
}

ControlFlow::<Never>::Continue(())
});

for error in errors {
diagnostics.push(diagnostic_to_string(file_name, input_code, error));
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_json_syntax/src/syntax_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
//!
//! This is a simple wrapper around the `rowan` crate which does most of the heavy lifting and is language agnostic.
use crate::{AnyJsonValue, JsonSyntaxKind};
use crate::{JsonRoot, JsonSyntaxKind};
use biome_rowan::Language;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct JsonLanguage;

impl Language for JsonLanguage {
type Kind = JsonSyntaxKind;
type Root = AnyJsonValue;
type Root = JsonRoot;
}

pub type JsonSyntaxNode = biome_rowan::SyntaxNode<JsonLanguage>;
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_lsp/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,10 @@ impl ServerFactory {
builder = builder.custom_method("biome/rage", LSPServer::rage);

workspace_method!(builder, file_features);
workspace_method!(builder, project_features);
workspace_method!(builder, is_path_ignored);
workspace_method!(builder, update_settings);
workspace_method!(builder, project_features);
workspace_method!(builder, open_file);
workspace_method!(builder, get_syntax_tree);
workspace_method!(builder, get_control_flow_graph);
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_migrate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ mod test {

let parsed = parse_json(source, JsonParserOptions::default());

migrate_configuration(&parsed.tree().value().unwrap(), Path::new(""), |signal| {
migrate_configuration(&parsed.tree(), Path::new(""), |signal| {
for action in signal.actions() {
let new_code = action.mutation.commit();
eprintln!("{new_code}");
Expand Down
Loading

0 comments on commit 1f5e239

Please sign in to comment.