Skip to content

Add infrastructure to enrich errors with hints - #1486

Merged
laurmaedje merged 13 commits into
typst:mainfrom
Mafii:hint-diagnostics
Jun 24, 2023
Merged

laurmaedje merged 13 commits into
typst:mainfrom
Mafii:hint-diagnostics

Conversation

@Mafii

@Mafii Mafii commented Jun 13, 2023 •

Copy link
Copy Markdown
Contributor

Followup for #1456.

Goals during implementation:

  • As little changes to existing code as possible, as few changes in signatures as possible
    • I did refactor some test code however - feel free to critique!
  • Incremental shifts are possible - any existing code must be easily enriched with hints without huge changes
  • Hints always belong to errors, and there can be as many as preferred
  • Hints are currently codespan_reporting labels, but this can theoretically be changed in the future
  • The typ-file based tests can be extended with expected hints and they fail if a hint is not emitted or not annotated
    • Hint validation (for un-annotated output) can be disabled to avoid cluttering duplicated hints in technical tests

I did evaluate some more complex options (like a new result type) but nothing was convenient, really. There are some drafts in my fork but I don't think they're worth looking at.

What can be done after this:

  • All "did you" messages can be converted into hints
  • Richer hint output in the cli could be an option, but this might require moving away from codespan_reporting or simply abusing it by printing an additoinal information output as hint, which will then be unrelated to the error, at least technically.

Comment thread src/diag.rs Resolved
Comment thread src/diag.rs Resolved
Comment thread tests/src/tests.rs Resolved
Comment thread tests/src/tests.rs Resolved
Comment thread tests/src/tests.rs Resolved
Comment thread tests/src/tests.rs Resolved
@laurmaedje
laurmaedje merged commit 2e03fb3 into typst:main Jun 24, 2023
@laurmaedje

Copy link
Copy Markdown
Member

Thanks, looks good!

Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants