-
-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(format/html): add
quick_test
to formatter crate (#3777)
- Loading branch information
Showing
11 changed files
with
170 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use biome_formatter_test::TestFormatLanguage; | ||
use biome_fs::BiomePath; | ||
use biome_html_formatter::context::HtmlFormatContext; | ||
use biome_html_formatter::HtmlFormatLanguage; | ||
use biome_html_parser::parse_html; | ||
use biome_html_syntax::{HtmlFileSource, HtmlLanguage}; | ||
use biome_parser::AnyParse; | ||
use biome_service::{ | ||
settings::{ServiceLanguage, Settings}, | ||
workspace::DocumentFileSource, | ||
}; | ||
|
||
pub struct HtmlTestFormatLanguage { | ||
#[allow(dead_code)] | ||
source_type: HtmlFileSource, | ||
} | ||
|
||
impl HtmlTestFormatLanguage { | ||
pub fn new(source_type: HtmlFileSource) -> Self { | ||
HtmlTestFormatLanguage { source_type } | ||
} | ||
} | ||
|
||
impl TestFormatLanguage for HtmlTestFormatLanguage { | ||
type ServiceLanguage = HtmlLanguage; | ||
type Context = HtmlFormatContext; | ||
type FormatLanguage = HtmlFormatLanguage; | ||
|
||
fn parse(&self, text: &str) -> AnyParse { | ||
parse_html(text).into() | ||
} | ||
|
||
fn to_format_language( | ||
&self, | ||
settings: &Settings, | ||
file_source: &DocumentFileSource, | ||
) -> Self::FormatLanguage { | ||
let options = Self::ServiceLanguage::resolve_format_options( | ||
Some(&settings.formatter), | ||
Some(&settings.override_settings), | ||
None, | ||
&BiomePath::new(""), | ||
file_source, | ||
); | ||
HtmlFormatLanguage::new(options) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use biome_formatter::{AttributePosition, IndentStyle, LineWidth}; | ||
use biome_formatter_test::check_reformat::CheckReformat; | ||
use biome_html_formatter::context::HtmlFormatOptions; | ||
use biome_html_formatter::{format_node, HtmlFormatLanguage}; | ||
use biome_html_parser::parse_html; | ||
use biome_html_syntax::HtmlFileSource; | ||
|
||
mod language { | ||
include!("language.rs"); | ||
} | ||
|
||
#[ignore] | ||
#[test] | ||
// use this test check if your snippet prints as you wish, without using a snapshot | ||
fn quick_test() { | ||
let src = r#" | ||
<div> | ||
<p>hello | ||
</p> | ||
</div> | ||
"#; | ||
let source_type = HtmlFileSource::html(); | ||
let tree = parse_html(src); | ||
let options = HtmlFormatOptions::new() | ||
.with_indent_style(IndentStyle::Space) | ||
.with_line_width(LineWidth::try_from(80).unwrap()) | ||
.with_attribute_position(AttributePosition::Multiline); | ||
|
||
let doc = format_node(options.clone(), &tree.syntax()).unwrap(); | ||
let result = doc.print().unwrap(); | ||
|
||
println!("{}", doc.into_document()); | ||
eprintln!("{}", result.as_code()); | ||
|
||
CheckReformat::new( | ||
&tree.syntax(), | ||
result.as_code(), | ||
"testing", | ||
&language::HtmlTestFormatLanguage::new(source_type), | ||
HtmlFormatLanguage::new(options), | ||
) | ||
.check_reformat(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use biome_html_formatter::HtmlFormatOptions; | ||
use biome_html_syntax::HtmlLanguage; | ||
|
||
use crate::settings::ServiceLanguage; | ||
|
||
impl ServiceLanguage for HtmlLanguage { | ||
type FormatterSettings = (); | ||
type LinterSettings = (); | ||
type OrganizeImportsSettings = (); | ||
type FormatOptions = HtmlFormatOptions; | ||
type ParserSettings = (); | ||
type EnvironmentSettings = (); | ||
|
||
fn lookup_settings( | ||
_languages: &crate::settings::LanguageListSettings, | ||
) -> &crate::settings::LanguageSettings<Self> { | ||
todo!() | ||
} | ||
|
||
fn resolve_format_options( | ||
_global: Option<&crate::settings::FormatSettings>, | ||
_overrides: Option<&crate::settings::OverrideSettings>, | ||
_language: Option<&Self::FormatterSettings>, | ||
_path: &biome_fs::BiomePath, | ||
_file_source: &super::DocumentFileSource, | ||
) -> Self::FormatOptions { | ||
// TODO: actually resolve options | ||
HtmlFormatOptions::default() | ||
} | ||
|
||
fn resolve_analyzer_options( | ||
_global: Option<&crate::settings::Settings>, | ||
_linter: Option<&crate::settings::LinterSettings>, | ||
_overrides: Option<&crate::settings::OverrideSettings>, | ||
_language: Option<&Self::LinterSettings>, | ||
_path: &biome_fs::BiomePath, | ||
_file_source: &super::DocumentFileSource, | ||
) -> biome_analyze::AnalyzerOptions { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters