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

@ -297,11 +297,10 @@ pub fn diagnostics(
) -> Vec<Diagnostic> {
let _p = tracing::span!(tracing::Level::INFO, "diagnostics").entered();
let sema = Semantics::new(db);
let parse = db.parse(file_id);
let mut res = Vec::new();
// [#34344] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily.
res.extend(parse.errors().into_iter().take(128).map(|err| {
res.extend(db.parse_errors(file_id).as_deref().into_iter().flatten().take(128).map(|err| {
Diagnostic::new(
DiagnosticCode::RustcHardError("syntax-error"),
format!("Syntax Error: {err}"),
@ -340,7 +339,8 @@ pub fn diagnostics(
AnyDiagnostic::MacroDefError(d) => handlers::macro_error::macro_def_error(&ctx, &d),
AnyDiagnostic::MacroError(d) => handlers::macro_error::macro_error(&ctx, &d),
AnyDiagnostic::MacroExpansionParseError(d) => {
res.extend(d.errors.iter().take(32).map(|err| {
// FIXME: Point to the correct error span here, not just the macro-call name
res.extend(d.errors.iter().take(16).map(|err| {
{
Diagnostic::new(
DiagnosticCode::RustcHardError("syntax-error"),