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: language reference links and examples in docstrings #7240

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

david-christiansen
Copy link
Contributor

@david-christiansen david-christiansen commented Feb 26, 2025

This PR adds a canonical syntax for linking to sections in the language reference along with formatting of examples in docstrings according to the docstring style guide.

Docstrings are now pre-processed as follows:

  • Output included as part of examples is shown with leading line comment indicators in hovers

  • URLs of the form lean-manual://section/section-id are rewritten to links that point at the corresponding section in the Lean reference manual. The reference manual's base URL is configured when Lean is built and can be overridden with the LEAN_MANUAL_ROOT environment variable. This way, releases can point documentation links to the correct snapshot, and users can use their own, e.g. for offline reading.

Manual URLs in docstrings are validated when the docstring is added. The presence of a URL starting with lean-manual:// that is not a syntactically valid section link causes the docstring to be rejected. This allows for future extensibility to the set of allowed links. There is no validation that the linked-to section actually exists. To provide the best possible error messages in case of validation failures, Lean.addDocString now takes a TSyntax ``docComment instead of a string; clients should adapt by removing the step that extracts the string, or by calling the lower-level addDocStringCore in cases where the docstring in question is obtained from the environment and has thus already had its links validated.

A stage0 update is required to make the documentation site configurable at build time and for releases. A local commit on top of a stage0 update that will be sent in a followup PR includes the configurable reference manual root and updates to the release checklist.

Docstrings are now pre-processed as follows:

 * Output included as part of examples is shown with leading line
 comment indicators in hovers

 * URLs of the form `lean-manual://section/section-id` are rewritten
 to links that point at the corresponding section in the Lean
 reference manual. The reference manual's base URL is configured when
 Lean is built and can be overridden with the `LEAN_MANUAL_ROOT`
 environment variable. This way, releases can point documentation
 links to the correct snapshot, and users can use their own, e.g. for
 offline reading.

Manual URLs in docstrings are validated when the docstring is
added. The presence of a URL starting with `lean-manual://` that is
not a syntactically valid section link causes the docstring to be
rejected. This allows for future extensibility to the set of allowed
links. There is no validation that the linked-to section actually
exists.

A stage0 update will be required to make the documentation site
configurable at build time and for releases.
@david-christiansen david-christiansen added the changelog-server Language server, widgets, and IDE extensions label Feb 26, 2025
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Feb 26, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Feb 26, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Feb 26, 2025
@leanprover-community-bot leanprover-community-bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Feb 26, 2025
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Feb 26, 2025

Mathlib CI status (docs):

-/
def rewriteManualLinks (docString : String) : BaseIO String := do
let (errs, str) ← rewriteManualLinksCore docString
assert! errs.isEmpty
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mhuisi I wonder whether this line should instead append an error report to the docstring in question. The risk is that this might be missed in cases where docstrings are added via the low-level API by metaprogramming. On the other hand, it may be easier to recover from. I think I'll push a commit that does this, and we can revert it if you disagree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 9de9505. I think it's much better.

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Feb 26, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Feb 26, 2025
@david-christiansen
Copy link
Contributor Author

Please hold off on merges until after the upcoming RC is out. It's too late in the process to add a step to the release process this time around.

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Feb 26, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan changelog-server Language server, widgets, and IDE extensions toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants