Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler): rework diagnostics to support multiple files #414

Merged
merged 50 commits into from
Jan 30, 2023

Conversation

goto-bus-stop
Copy link
Member

@goto-bus-stop goto-bus-stop commented Jan 10, 2023

miette doesn't support referencing multiple files in one error, so we sadly can't use it directly. Most errors in executable documents will reference another document.

Without miette's derives, we need some other way to represent shared diagnostic properties like labels and help text. For now this PR uses:

pub struct ApolloDiagnostic {
    pub location: HirNodeLocation, // ← may be removed as the first Label will usually have the same location
    pub labels: Vec<Label>,
    pub help: Option<String>,
    pub data: DiagnosticData,
}

DiagnosticData is an enum with the different diagnostic types and specific information about them.
With that structure we need to format labels wherever we create an error.

I converted a part of the validation so far and explored using ariadne for displaying errors. I'll continue to work on ariadne output first in case the diagnostic data structure needs to change. Then some API polish, maybe we can reduce the boilerplatyness of this implementation a bit.

Todos:

  • We need an ariadne release (using a fork)
  • Tests now rely on the order they are run in to work, due to the global FileId counter -- they should be checked some other way. Maybe ApolloDiagnostic Debug impl can censor them consistently or we just make FileId display as a constant value … or we change the test output to use source strings wherever a DiagnosticLocation occurs … or something else
    Reset FileId between directory tests #437

@goto-bus-stop
Copy link
Member Author

Something still wrong in printing the line/column offsets, but this is an example of a multi-file diagnostic:
image

@lrlna
Copy link
Member

lrlna commented Jan 12, 2023

ooooohh that is already looking real good @goto-bus-stop !

@goto-bus-stop
Copy link
Member Author

OK, we're really getting somewhere:
image

Time to resolve some conflicts ;p

@goto-bus-stop
Copy link
Member Author

This can be reviewed but it still has some blockers, will maintain checklist in OP

@goto-bus-stop goto-bus-stop marked this pull request as ready for review January 13, 2023 16:43
@lrlna
Copy link
Member

lrlna commented Jan 16, 2023

is there a way to get ariadne to expand its spans?

There are a couple of places where the fields get swallowed when diagnostics are expanded, and the error becomes a lot more confusing.

Some examples:

duplicate names with miette

duplicate_names

duplicate names with ariadne

duplicate_names_multi_file

expected ident with miette

expected_identifier

expected ident with ariadne

expected_identifier_multi_file

unexpected field with miette

size_field

unexpected field with ariadne

(nice addition of original Query definition here though ;)
size_field_multi_file

Copy link
Member

@lrlna lrlna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some error standardisation here

crates/apollo-compiler/src/diagnostics.rs Outdated Show resolved Hide resolved
crates/apollo-compiler/src/diagnostics.rs Outdated Show resolved Hide resolved
crates/apollo-compiler/src/diagnostics.rs Outdated Show resolved Hide resolved
crates/apollo-compiler/src/diagnostics.rs Outdated Show resolved Hide resolved
crates/apollo-compiler/src/diagnostics.rs Outdated Show resolved Hide resolved
crates/apollo-compiler/src/diagnostics.rs Outdated Show resolved Hide resolved
Co-authored-by: Iryna Shestak <shestak.irina@gmail.com>
@lrlna lrlna added the apollo-compiler issues/PRs pertaining to semantic analysis & validation label Jan 17, 2023
@goto-bus-stop
Copy link
Member Author

so at this stage it works and everything, but we have less context in error messages.

@lrlna
Copy link
Member

lrlna commented Jan 30, 2023

@goto-bus-stop ok, let's merge this in, and in our continued validation process work on adding more context to ariadne

@goto-bus-stop goto-bus-stop changed the title Multi-file diagnostics feat(compiler): rework diagnostics to support multiple files Jan 30, 2023
@goto-bus-stop goto-bus-stop merged commit b04f1df into main Jan 30, 2023
@goto-bus-stop goto-bus-stop deleted the multi-file-errors branch January 30, 2023 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apollo-compiler issues/PRs pertaining to semantic analysis & validation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants