Skip to content

Add infrastructure for compiler warnings - #1731

Merged
laurmaedje merged 5 commits into
typst:mainfrom
lolstork:compile-warnings
Jul 19, 2023
Merged

laurmaedje merged 5 commits into
typst:mainfrom
lolstork:compile-warnings

Conversation

@lolstork

Copy link
Copy Markdown
Contributor

Resolves #600. This PR is largely adapted from #990, but updated and compatible with the current codebase (hints, etc.). Also, for simplicity, this PR does not include the same Rule abstraction as #990.

The implementation is accomplished with a linting pass before primary compilation. It additionally adds a warning for empty bold sections and a test to verify functionality.

Example output:

warning: no text within stars
  ┌─ /test.typ:1:0
  │
1 │ **supposedly bold text**
  │ ^^
  │
  = hint: using multiple consecutive stars (e.g. **) has no additional effect

warning: no text within stars
  ┌─ /test.typ:1:22
  │
1 │ **supposedly bold text**
  │                       ^^
  │
  = hint: using multiple consecutive stars (e.g. **) has no additional effect

@laurmaedje

Copy link
Copy Markdown
Member

I think ideally (and I should have commented this on the earlier PR), warnings wouldn't be returned, but handled as tracked side effects with TrackedMut. This would make it possible to emit warnings from anywhere in the compilation, also for imported files or during evaluation. I think this could be integrated into the existing Tracer struct without too much hassle and while keeping most of the PR intact. I'd also be happy to provide guidance on this.

Comment thread crates/typst/src/lint.rs Resolved
@lolstork

Copy link
Copy Markdown
Contributor Author

Will look into this. Thanks for offering help, will definitely ping you on discord if I run into issues.

@laurmaedje

Copy link
Copy Markdown
Member

My syntax crate refactoring created a bunch of conflicts, sorry about that. No major conflict from the looks of it though.

lolstork added 3 commits July 18, 2023 22:35
Implemented with a linting pass before primary compilation.

Additionally added a warning for empty bold sections and a test to verify functionality.
Now uses a `Warnings` struct that is tracked by comemo
@lolstork

Copy link
Copy Markdown
Contributor Author

No worries, I just resolved them. They were all fairly simple. Hopefully it still works!

Refactored `Tracer` into separate file and changed `Vec`s in `Tracer` to `EcoVec`s
Comment thread crates/typst-cli/src/compile.rs Resolved
Comment thread tests/src/tests.rs Resolved
@laurmaedje
laurmaedje merged commit b37c1e2 into typst:main Jul 19, 2023
@laurmaedje

Copy link
Copy Markdown
Member

Thank you, I'm very happy how this turned out. :)

@lolstork
lolstork deleted the compile-warnings branch July 19, 2023 13:30
@tingerrr tingerrr mentioned this pull request Oct 31, 2023
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.

Add warnings and hints to the error reporting

2 participants