From 931960e6556da9f554a947b1c40bb1310e7533ad Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 6 Nov 2024 08:40:49 +0000 Subject: [PATCH] feat: enable handling of grit files (#4473) --- .github/workflows/repository_dispatch.yml | 2 +- crates/biome_cli/Cargo.toml | 1 - crates/biome_grit_formatter/Cargo.toml | 2 +- crates/biome_service/Cargo.toml | 2 -- crates/biome_service/src/file_handlers/mod.rs | 6 ++--- crates/biome_service/tests/workspace.rs | 24 +++++++++++++++++++ crates/biome_wasm/Cargo.toml | 1 - 7 files changed, 28 insertions(+), 10 deletions(-) diff --git a/.github/workflows/repository_dispatch.yml b/.github/workflows/repository_dispatch.yml index b6497dd89984..7e66acfe4a02 100644 --- a/.github/workflows/repository_dispatch.yml +++ b/.github/workflows/repository_dispatch.yml @@ -39,7 +39,7 @@ jobs: run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - name: Build WASM module for the web - run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-web --target web --profiling --scope biomejs crates/biome_wasm --features experimental-html,experimental-grit + run: wasm-pack build --out-dir ../../packages/@biomejs/wasm-web --target web --profiling --scope biomejs crates/biome_wasm --features experimental-html # https://github.com/actions/cache/issues/342 - name: Clear old wasm-pack cache diff --git a/crates/biome_cli/Cargo.toml b/crates/biome_cli/Cargo.toml index b316ec778c34..7a5ba96481f4 100644 --- a/crates/biome_cli/Cargo.toml +++ b/crates/biome_cli/Cargo.toml @@ -78,7 +78,6 @@ tokio = { workspace = true, features = ["io-util"] } [features] docgen = ["bpaf/docgen"] -experimental-grit = ["biome_service/experimental-grit"] experimental-html = ["biome_service/experimental-html"] [lints] diff --git a/crates/biome_grit_formatter/Cargo.toml b/crates/biome_grit_formatter/Cargo.toml index eaebbafeaa7c..0e9f3c2c0504 100644 --- a/crates/biome_grit_formatter/Cargo.toml +++ b/crates/biome_grit_formatter/Cargo.toml @@ -24,7 +24,7 @@ biome_fs = { path = "../biome_fs" } biome_grit_factory = { path = "../biome_grit_factory" } biome_grit_parser = { path = "../biome_grit_parser" } biome_parser = { path = "../biome_parser" } -biome_service = { path = "../biome_service", features = ["experimental-grit"] } +biome_service = { path = "../biome_service" } countme = { workspace = true, features = ["enable"] } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } diff --git a/crates/biome_service/Cargo.toml b/crates/biome_service/Cargo.toml index 9ca9261aab40..b1b7df54ed57 100644 --- a/crates/biome_service/Cargo.toml +++ b/crates/biome_service/Cargo.toml @@ -70,7 +70,6 @@ smallvec = { workspace = true, features = ["serde"] } tracing = { workspace = true, features = ["attributes", "log"] } [features] -experimental-grit = [] experimental-html = [] schema = [ @@ -83,7 +82,6 @@ schema = [ "biome_css_syntax/schema", "biome_graphql_syntax/schema", "biome_grit_syntax/schema", - ] [dev-dependencies] diff --git a/crates/biome_service/src/file_handlers/mod.rs b/crates/biome_service/src/file_handlers/mod.rs index 3302d875d154..594b37168ae3 100644 --- a/crates/biome_service/src/file_handlers/mod.rs +++ b/crates/biome_service/src/file_handlers/mod.rs @@ -161,7 +161,6 @@ impl DocumentFileSource { return Ok(file_source.into()); } - #[cfg(feature = "experimental-grit")] if let Ok(file_source) = GritFileSource::try_from_extension(extension) { return Ok(file_source.into()); } @@ -192,7 +191,6 @@ impl DocumentFileSource { if let Ok(file_source) = HtmlFileSource::try_from_language_id(language_id) { return Ok(file_source.into()); } - #[cfg(feature = "experimental-grit")] if let Ok(file_source) = GritFileSource::try_from_language_id(language_id) { return Ok(file_source.into()); } @@ -350,9 +348,9 @@ impl DocumentFileSource { }, DocumentFileSource::Css(_) | DocumentFileSource::Graphql(_) - | DocumentFileSource::Json(_) => true, + | DocumentFileSource::Json(_) + | DocumentFileSource::Grit(_) => true, DocumentFileSource::Html(_) => cfg!(feature = "experimental-html"), - DocumentFileSource::Grit(_) => cfg!(feature = "experimental-grit"), DocumentFileSource::Unknown => false, } } diff --git a/crates/biome_service/tests/workspace.rs b/crates/biome_service/tests/workspace.rs index 169302b976ee..1ab1b73ec79c 100644 --- a/crates/biome_service/tests/workspace.rs +++ b/crates/biome_service/tests/workspace.rs @@ -248,4 +248,28 @@ type User { let diagnostics = result.unwrap().diagnostics; assert_eq!(diagnostics.len(), 1) } + + #[test] + fn pull_grit_debug_info() { + let workspace = create_server(); + + let grit_file = FileGuard::open( + workspace.as_ref(), + OpenFileParams { + path: BiomePath::new("file.grit"), + content: r#"`function ($args) { $body }` where { + $args <: contains `x` +}"# + .into(), + version: 0, + document_file_source: None, + }, + ) + .unwrap(); + let result = grit_file.get_syntax_tree(); + assert!(result.is_ok()); + let syntax = result.unwrap().ast; + + assert!(syntax.starts_with("GritRoot")) + } } diff --git a/crates/biome_wasm/Cargo.toml b/crates/biome_wasm/Cargo.toml index 522491d3a989..f1bd36d1c8f8 100644 --- a/crates/biome_wasm/Cargo.toml +++ b/crates/biome_wasm/Cargo.toml @@ -17,7 +17,6 @@ crate-type = ["cdylib", "rlib"] [features] default = ["console_error_panic_hook"] -experimental-grit = ["biome_service/experimental-grit"] experimental-html = ["biome_service/experimental-html"] [dependencies]