Error out when selecting unknown styles

This commit is contained in:
Tobias Hunger 2022-01-20 14:39:16 +01:00 committed by Tobias Hunger
parent f9fd523583
commit d64dfa500c
3 changed files with 33 additions and 1 deletions

View file

@ -22,6 +22,10 @@ impl<'a> VirtualFile<'a> {
}
}
pub fn styles() -> Vec<&'static str> {
builtin_library::styles()
}
pub fn load_file<'a>(path: &'a std::path::Path) -> Option<VirtualFile<'static>> {
match path.strip_prefix("builtin:/") {
Ok(builtin_path) => builtin_library::load_builtin_file(builtin_path),
@ -44,6 +48,20 @@ mod builtin_library {
use super::VirtualFile;
pub(crate) fn styles() -> Vec<&'static str> {
widget_library()
.iter()
.filter_map(|d| {
let style = d.0;
if d.1.iter().any(|f| f.path == "sixtyfps_widgets.60") {
Some(style)
} else {
None
}
})
.collect()
}
pub(crate) fn load_builtin_file(
builtin_path: &std::path::Path,
) -> Option<VirtualFile<'static>> {

View file

@ -111,6 +111,7 @@ pub async fn compile_syntax_node(
let mut loader =
typeloader::TypeLoader::new(global_type_registry, &compiler_config, &mut diagnostics);
let foreign_imports =
loader.load_dependencies_recursively(&doc_node, &mut diagnostics, &type_registry).await;

View file

@ -9,10 +9,10 @@ use std::rc::Rc;
use crate::diagnostics::{BuildDiagnostics, Spanned};
use crate::object_tree::{self, Document};
use crate::parser;
use crate::parser::{syntax_nodes, NodeOrToken, SyntaxKind, SyntaxToken};
use crate::typeregister::TypeRegister;
use crate::CompilerConfiguration;
use crate::{fileaccess, parser};
/// Storage for a cache of all loaded documents
#[derive(Default)]
@ -99,6 +99,19 @@ impl<'a> TypeLoader<'a> {
Cow::from("fluent")
});
let known_styles = fileaccess::styles();
if !known_styles.contains(&style.as_ref()) {
diag.push_diagnostic_with_span(
format!(
"Style {} in not known. Use one of [{}] instead",
&style,
known_styles.join(", ")
),
Default::default(),
crate::diagnostics::DiagnosticLevel::Error,
);
}
Self { global_type_registry, compiler_config, style, all_documents: Default::default() }
}