Skip to content

Commit f122454

Browse files
chore: cleanup and better docs for #10479 (#10504)
This PR cleans up a half-reverted refactor and adds documentation to #10479.
1 parent 02f4821 commit f122454

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/Lean/Elab/InfoTree/Types.lean

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,23 @@ inductive DocElabKind where
212212
deriving Repr
213213

214214
/--
215-
Indicates that an extensible document elaborator was used here.
215+
Indicates that an extensible document elaborator was used. This info is applied to the name on a
216+
role, directive, code block, or command, and is used to generate the hover.
217+
218+
A `TermInfo` would not give the correct hover for a few reasons:
219+
1. The name used to invoke a document extension is not necessarily the name of the elaborator that
220+
was used, but the elaborator's docstring should be shown rather than that of the name as
221+
written.
222+
2. The underlying elaborator's Lean type is not an appropriate signature to show to users.
216223
-/
217224
structure DocElabInfo extends ElabInfo where
218225
name : Name
219226
kind : DocElabKind
220227

221228
/--
222-
Indicates that a piece of syntax was elaborated as documentation.
229+
Indicates that a piece of syntax was elaborated as documentation. This info is used for ordinary
230+
documentation constructs, such as paragraphs, list items, and links. It can be used to determine
231+
that a given piece of documentation syntax in fact has been elaborated.
223232
-/
224233
structure DocInfo extends ElabInfo where
225234

src/Lean/Parser/Term/Basic.lean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ public import Lean.Parser.Level
1111
public import Lean.Parser.Term.Doc
1212
meta import Lean.Parser.Basic
1313

14+
/-!
15+
This module contains the bare minimum of term syntax that's required to get documentation syntax to
16+
parse, namely structure initializers and their dependencies.
17+
18+
This matters because some term syntax (such as `let rec`) includes docstrings, but docstrings
19+
include metadata blocks that themselves include a structure initializer. Separating these layers
20+
prevents an import cycle.
21+
22+
The remaining term syntax is found in `Lean.Parser.Term`. It may freely make use of documentation
23+
comments.
24+
-/
1425

1526
public section
1627

src/Lean/Server/FileWorker/SemanticHighlighting.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ partial def collectSyntaxBasedSemanticTokens : (stx : Syntax) → Array LeanSema
260260
open Lean.Doc.Syntax in
261261
/-- Collects all semantic tokens from the given `Elab.InfoTree`. -/
262262
def collectInfoBasedSemanticTokens (i : Elab.InfoTree) : Array LeanSemanticToken :=
263-
Array.flatten <| List.toArray <| i.deepestNodes fun _ info _ => do
263+
List.toArray <| i.deepestNodes fun _ info _ => do
264264
let .ofTermInfo ti := info
265265
| none
266266
let .original .. := ti.stx.getHeadInfo
@@ -271,11 +271,11 @@ def collectInfoBasedSemanticTokens (i : Elab.InfoTree) : Array LeanSemanticToken
271271
-- Recall that `isAuxDecl` is an auxiliary declaration used to elaborate a recursive definition.
272272
if localDecl.isAuxDecl then
273273
if ti.isBinder then
274-
return #[⟨ti.stx, SemanticTokenType.function⟩]
274+
return ⟨ti.stx, SemanticTokenType.function⟩
275275
else if ! localDecl.isImplementationDetail then
276-
return #[⟨ti.stx, SemanticTokenType.variable⟩]
276+
return ⟨ti.stx, SemanticTokenType.variable⟩
277277
if ti.stx.getKind == Parser.Term.identProjKind then
278-
return #[⟨ti.stx, SemanticTokenType.property⟩]
278+
return ⟨ti.stx, SemanticTokenType.property⟩
279279
none
280280

281281
def computeSemanticTokens (doc : EditableDocument) (beginPos : String.Pos)

0 commit comments

Comments
 (0)