From 18742afdd9472704ffe55f480c2d27f6d0db41ac Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Wed, 18 Sep 2024 07:15:27 -0400 Subject: [PATCH] feat(html): add `experimental-html` feature flag to enable html file handler --- crates/biome_cli/Cargo.toml | 1 + crates/biome_service/Cargo.toml | 1 + crates/biome_service/src/file_handlers/html.rs | 14 +++++++++----- crates/biome_service/src/file_handlers/mod.rs | 17 +++++++++++------ crates/biome_service/src/settings.rs | 2 ++ 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/crates/biome_cli/Cargo.toml b/crates/biome_cli/Cargo.toml index 21b26fcf35c4..6e0ffcad924e 100644 --- a/crates/biome_cli/Cargo.toml +++ b/crates/biome_cli/Cargo.toml @@ -78,6 +78,7 @@ tokio = { workspace = true, features = ["io-util"] } [features] docgen = ["bpaf/docgen"] +experimental-html = ["biome_service/experimental-html"] [lints] workspace = true diff --git a/crates/biome_service/Cargo.toml b/crates/biome_service/Cargo.toml index fb3bb96f8035..e62adc3eeb6f 100644 --- a/crates/biome_service/Cargo.toml +++ b/crates/biome_service/Cargo.toml @@ -76,6 +76,7 @@ schema = [ "biome_css_syntax/schema", "biome_graphql_syntax/schema", ] +experimental-html = [] [dev-dependencies] insta = { workspace = true } diff --git a/crates/biome_service/src/file_handlers/html.rs b/crates/biome_service/src/file_handlers/html.rs index 9d39e9714f15..45a4dee8bc00 100644 --- a/crates/biome_service/src/file_handlers/html.rs +++ b/crates/biome_service/src/file_handlers/html.rs @@ -1,3 +1,4 @@ +use biome_analyze::{AnalyzerConfiguration, AnalyzerOptions}; use biome_formatter::Printed; use biome_fs::BiomePath; use biome_html_formatter::{format_node, HtmlFormatOptions}; @@ -25,9 +26,9 @@ impl ServiceLanguage for HtmlLanguage { type EnvironmentSettings = (); fn lookup_settings( - _languages: &crate::settings::LanguageListSettings, + languages: &crate::settings::LanguageListSettings, ) -> &crate::settings::LanguageSettings { - todo!() + &languages.html } fn resolve_format_options( @@ -46,10 +47,13 @@ impl ServiceLanguage for HtmlLanguage { _linter: Option<&crate::settings::LinterSettings>, _overrides: Option<&crate::settings::OverrideSettings>, _language: Option<&Self::LinterSettings>, - _path: &biome_fs::BiomePath, + path: &biome_fs::BiomePath, _file_source: &super::DocumentFileSource, - ) -> biome_analyze::AnalyzerOptions { - todo!() + ) -> AnalyzerOptions { + AnalyzerOptions { + configuration: AnalyzerConfiguration::default(), + file_path: path.to_path_buf(), + } } } diff --git a/crates/biome_service/src/file_handlers/mod.rs b/crates/biome_service/src/file_handlers/mod.rs index 2da2abb62147..76e4a0210975 100644 --- a/crates/biome_service/src/file_handlers/mod.rs +++ b/crates/biome_service/src/file_handlers/mod.rs @@ -144,9 +144,10 @@ impl DocumentFileSource { if let Ok(file_source) = GraphqlFileSource::try_from_extension(extension) { return Ok(file_source.into()); } - //if let Ok(file_source) = HtmlFileSource::try_from_extension(extension) { - // return Ok(file_source.into()); - //} + #[cfg(feature = "experimental-html")] + if let Ok(file_source) = HtmlFileSource::try_from_extension(extension) { + return Ok(file_source.into()); + } Err(FileSourceError::UnknownExtension) } @@ -170,9 +171,10 @@ impl DocumentFileSource { if let Ok(file_source) = GraphqlFileSource::try_from_language_id(language_id) { return Ok(file_source.into()); } - //if let Ok(file_source) = HtmlFileSource::try_from_language_id(language_id) { - // return Ok(file_source.into()); - //} + #[cfg(feature = "experimental-html")] + if let Ok(file_source) = HtmlFileSource::try_from_language_id(language_id) { + return Ok(file_source.into()); + } Err(FileSourceError::UnknownLanguageId) } @@ -314,7 +316,10 @@ impl DocumentFileSource { DocumentFileSource::Css(_) | DocumentFileSource::Graphql(_) | DocumentFileSource::Json(_) => true, + #[cfg(not(feature = "experimental-html"))] DocumentFileSource::Html(_) => false, + #[cfg(feature = "experimental-html")] + DocumentFileSource::Html(_) => true, DocumentFileSource::Unknown => false, } } diff --git a/crates/biome_service/src/settings.rs b/crates/biome_service/src/settings.rs index 7b3fb1cd0fa1..8eaf70178351 100644 --- a/crates/biome_service/src/settings.rs +++ b/crates/biome_service/src/settings.rs @@ -23,6 +23,7 @@ use biome_formatter::{ use biome_fs::BiomePath; use biome_graphql_formatter::context::GraphqlFormatOptions; use biome_graphql_syntax::GraphqlLanguage; +use biome_html_syntax::HtmlLanguage; use biome_js_formatter::context::JsFormatOptions; use biome_js_parser::JsParserOptions; use biome_js_syntax::{JsFileSource, JsLanguage}; @@ -560,6 +561,7 @@ pub struct LanguageListSettings { pub json: LanguageSettings, pub css: LanguageSettings, pub graphql: LanguageSettings, + pub html: LanguageSettings, } impl From for LanguageSettings {