mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
Print the diagnostics in stderr for files which do not have span information
This commit is contained in:
parent
19458eb2e6
commit
2d016dffda
3 changed files with 25 additions and 16 deletions
|
@ -16,6 +16,6 @@ path = "lib.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
proc-macro2 = "1.0.17"
|
proc-macro2 = "1.0.17"
|
||||||
sixtyfps-compilerlib = { version = "=0.0.2", path = "../../../sixtyfps_compiler", features = ["proc_macro_span", "rust"] }
|
sixtyfps-compilerlib = { version = "=0.0.2", path = "../../../sixtyfps_compiler", features = ["proc_macro_span", "rust", "display-diagnostics"] }
|
||||||
spin_on = "0.1"
|
spin_on = "0.1"
|
||||||
|
|
||||||
|
|
|
@ -336,8 +336,7 @@ pub fn sixtyfps(stream: TokenStream) -> TokenStream {
|
||||||
spin_on::spin_on(compile_syntax_node(syntax_node, diag, compiler_config));
|
spin_on::spin_on(compile_syntax_node(syntax_node, diag, compiler_config));
|
||||||
//println!("{:#?}", tree);
|
//println!("{:#?}", tree);
|
||||||
if diag.has_error() {
|
if diag.has_error() {
|
||||||
diag.map_offsets_to_span(&tokens);
|
return report_diagnostics(diag, &tokens);
|
||||||
return diag.into_token_stream().into();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut result = generator::rust::generate(&root_component, &mut diag);
|
let mut result = generator::rust::generate(&root_component, &mut diag);
|
||||||
|
@ -353,10 +352,27 @@ pub fn sixtyfps(stream: TokenStream) -> TokenStream {
|
||||||
x.extend(quote! {const _ : Option<&'static str> = ::core::option_env!("SIXTYFPS_STYLE");});
|
x.extend(quote! {const _ : Option<&'static str> = ::core::option_env!("SIXTYFPS_STYLE");});
|
||||||
});
|
});
|
||||||
|
|
||||||
result
|
let diags = report_diagnostics(diag, &tokens);
|
||||||
.unwrap_or_else(|| {
|
result.map_or(diags, |r| r.into())
|
||||||
diag.map_offsets_to_span(&tokens);
|
}
|
||||||
diag.into_token_stream()
|
|
||||||
})
|
fn report_diagnostics(
|
||||||
.into()
|
diag: diagnostics::BuildDiagnostics,
|
||||||
|
span_map: &[parser::Token],
|
||||||
|
) -> TokenStream {
|
||||||
|
let mut result = TokenStream::new();
|
||||||
|
let mut needs_error = diag.has_error();
|
||||||
|
for mut file_diag in diag.into_iter() {
|
||||||
|
if file_diag.source.is_none() {
|
||||||
|
file_diag.map_offsets_to_span(span_map);
|
||||||
|
needs_error &= !file_diag.has_error();
|
||||||
|
result.extend(TokenStream::from(file_diag.into_token_stream()))
|
||||||
|
} else {
|
||||||
|
file_diag.print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if needs_error {
|
||||||
|
result.extend(TokenStream::from(quote!(compile_error! { "Error occured" })))
|
||||||
|
}
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
|
@ -473,13 +473,6 @@ impl BuildDiagnostics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "proc_macro_span")]
|
|
||||||
impl quote::ToTokens for BuildDiagnostics {
|
|
||||||
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
|
||||||
self.iter().for_each(|diag| diag.to_tokens(tokens))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Extend<FileDiagnostics> for BuildDiagnostics {
|
impl Extend<FileDiagnostics> for BuildDiagnostics {
|
||||||
fn extend<T: IntoIterator<Item = FileDiagnostics>>(&mut self, iter: T) {
|
fn extend<T: IntoIterator<Item = FileDiagnostics>>(&mut self, iter: T) {
|
||||||
for diag in iter {
|
for diag in iter {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue