Push macro-parsing error calculation out of fundamental queries

This commit is contained in:
Lukas Wirth 2024-05-13 16:56:26 +02:00
parent 067d9d995b
commit 56552f4839
15 changed files with 145 additions and 140 deletions

View file

@ -8,7 +8,7 @@ mod input;
use std::panic;
use salsa::Durability;
use syntax::{ast, Parse, SourceFile};
use syntax::{ast, Parse, SourceFile, SyntaxError};
use triomphe::Arc;
pub use crate::{
@ -62,6 +62,9 @@ pub trait SourceDatabase: FileLoader + std::fmt::Debug {
/// Parses the file into the syntax tree.
fn parse(&self, file_id: FileId) -> Parse<ast::SourceFile>;
/// Returns the set of errors obtained from parsing the file including validation errors.
fn parse_errors(&self, file_id: FileId) -> Option<Arc<[SyntaxError]>>;
/// The crate graph.
#[salsa::input]
fn crate_graph(&self) -> Arc<CrateGraph>;
@ -88,6 +91,14 @@ fn parse(db: &dyn SourceDatabase, file_id: FileId) -> Parse<ast::SourceFile> {
SourceFile::parse(&text, span::Edition::CURRENT)
}
fn parse_errors(db: &dyn SourceDatabase, file_id: FileId) -> Option<Arc<[SyntaxError]>> {
let errors = db.parse(file_id).errors();
match &*errors {
[] => None,
[..] => Some(errors.into()),
}
}
/// We don't want to give HIR knowledge of source roots, hence we extract these
/// methods into a separate DB.
#[salsa::query_group(SourceDatabaseExtStorage)]