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. --------- Co-authored-by: Marc Huisinga <mhuisi@protonmail.com>
95 lines
1.8 KiB
Text
95 lines
1.8 KiB
Text
import Lean
|
|
|
|
/-!
|
|
This file tests that the convention for Lean block examples is correctly displayed in hovers.
|
|
|
|
Blocks that are indicated as output should be distinguished from blocks that are indicated as code
|
|
when hovers are shown. This is done by prefixing them with line comment markers.
|
|
|
|
This occurs only in hovers, so that other clients of this information can apply their own
|
|
conventions.
|
|
-/
|
|
|
|
/-!
|
|
# Ordinary Formatting
|
|
-/
|
|
|
|
/--
|
|
Does something complicated with IO that involves output.
|
|
|
|
```lean example
|
|
#eval complicatedIOProgram
|
|
```
|
|
```output
|
|
Hello!
|
|
More output
|
|
```
|
|
-/
|
|
def complicatedIOProgram : IO Unit := do
|
|
--^ textDocument/hover
|
|
IO.println "Hello!"
|
|
IO.println "More output"
|
|
|
|
|
|
/-!
|
|
# Indentation
|
|
These tests check the handling of indentation for output blocks
|
|
-/
|
|
|
|
/--
|
|
Does something complicated with IO that involves output.
|
|
|
|
```lean example
|
|
#eval anotherComplicatedIOProgram
|
|
```
|
|
|
|
```output
|
|
Hello!
|
|
More output
|
|
```
|
|
-/
|
|
def anotherComplicatedIOProgram : IO Unit := do
|
|
--^ textDocument/hover
|
|
IO.println "Hello!"
|
|
IO.println " More output"
|
|
|
|
/--
|
|
Does something complicated with IO that involves output.
|
|
|
|
```lean example
|
|
#eval yetAnotherComplicatedIOProgram
|
|
```
|
|
|
|
```output
|
|
Hello!
|
|
More output
|
|
```
|
|
-/
|
|
def yetAnotherComplicatedIOProgram : IO Unit := do
|
|
--^ textDocument/hover
|
|
IO.println "Hello!"
|
|
IO.println " More output"
|
|
|
|
|
|
/-!
|
|
# Programmatic Access
|
|
|
|
This test ensures that when looking up the docstring programmatically, the output blocks are not rewritten.
|
|
-/
|
|
|
|
/--
|
|
info: Does something complicated with IO that involves output.
|
|
|
|
```lean example
|
|
#eval complicatedIOProgram
|
|
```
|
|
```output
|
|
Hello!
|
|
More output
|
|
```
|
|
-/
|
|
#guard_msgs in
|
|
open Lean Elab Command in
|
|
#eval show CommandElabM Unit from do
|
|
let str ← Lean.findDocString? (← getEnv) ``complicatedIOProgram
|
|
str.forM (IO.println ·)
|