Make the extraction of slint! macro as part of the compiler core

This includes slint-viewer, slint-interpreter (when loading path, not
string), slint-compiler.

(This would also include internal things such as
`import { Xxx } from "foo.rs"`, if we didn't check for .slint or .60
extension before)

But that doesn't include anything that's not opening the source by path
(so not the lsp which use its own representation coming from the editor,
or varius tools like the updater and fmt which also open the files
themselves)
This commit is contained in:
Olivier Goffart 2023-06-08 09:11:45 +02:00 committed by Olivier Goffart
parent 1c033e7d72
commit cb840660aa
5 changed files with 79 additions and 61 deletions

View file

@ -142,7 +142,7 @@ impl SourceFileInner {
pub type SourceFile = Rc<SourceFileInner>;
pub fn load_from_path(path: &Path) -> Result<String, Diagnostic> {
(if path == Path::new("-") {
let string = (if path == Path::new("-") {
let mut buffer = Vec::new();
let r = std::io::stdin().read_to_end(&mut buffer);
r.and_then(|_| {
@ -159,7 +159,20 @@ pub fn load_from_path(path: &Path) -> Result<String, Diagnostic> {
span: Default::default(),
},
level: DiagnosticLevel::Error,
})
})?;
if path.extension().map_or(false, |e| e == "rs") {
return crate::lexer::extract_rust_macro(string).ok_or_else(|| Diagnostic {
message: "No `slint!` macro".into(),
span: SourceLocation {
source_file: Some(SourceFileInner::from_path_only(path.to_owned())),
span: Default::default(),
},
level: DiagnosticLevel::Error,
});
}
Ok(string)
}
#[derive(Debug, Clone, Default)]