-
-
Notifications
You must be signed in to change notification settings - Fork 540
/
Copy pathhtml.rs
118 lines (104 loc) · 3.57 KB
/
html.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
use biome_formatter::Printed;
use biome_fs::BiomePath;
use biome_html_formatter::{format_node, HtmlFormatOptions};
use biome_html_parser::parse_html_with_cache;
use biome_html_syntax::HtmlLanguage;
use biome_parser::AnyParse;
use biome_rowan::NodeCache;
use crate::{
settings::{ServiceLanguage, Settings, WorkspaceSettingsHandle},
WorkspaceError,
};
use super::{
AnalyzerCapabilities, Capabilities, DebugCapabilities, DocumentFileSource, ExtensionHandler,
FormatterCapabilities, ParseResult, ParserCapabilities, SearchCapabilities,
};
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!()
}
}
#[derive(Debug, Default, PartialEq, Eq)]
pub(crate) struct HtmlFileHandler;
impl ExtensionHandler for HtmlFileHandler {
fn capabilities(&self) -> Capabilities {
Capabilities {
parser: ParserCapabilities { parse: Some(parse) },
debug: DebugCapabilities {
debug_syntax_tree: None,
debug_control_flow: None,
debug_formatter_ir: None,
},
analyzer: AnalyzerCapabilities {
lint: None,
code_actions: None,
rename: None,
fix_all: None,
organize_imports: None,
},
formatter: FormatterCapabilities {
format: Some(format),
format_range: None,
format_on_type: None,
},
search: SearchCapabilities { search: None },
}
}
}
fn parse(
_biome_path: &BiomePath,
file_source: DocumentFileSource,
text: &str,
_settings: Option<&Settings>,
cache: &mut NodeCache,
) -> ParseResult {
let parse = parse_html_with_cache(text, cache);
ParseResult {
any_parse: parse.into(),
language: Some(file_source),
}
}
#[tracing::instrument(level = "debug", skip(parse, settings))]
fn format(
biome_path: &BiomePath,
document_file_source: &DocumentFileSource,
parse: AnyParse,
settings: WorkspaceSettingsHandle,
) -> Result<Printed, WorkspaceError> {
let options = settings.format_options::<HtmlLanguage>(biome_path, document_file_source);
tracing::debug!("Format with the following options: \n{}", options);
let tree = parse.syntax();
let formatted = format_node(options, &tree)?;
match formatted.print() {
Ok(printed) => Ok(printed),
Err(error) => Err(WorkspaceError::FormatError(error.into())),
}
}