-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
63 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/- | ||
Copyright (c) 2022 Microsoft Corporation. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Mario Carneiro | ||
-/ | ||
import Lean.Elab.InfoTree.Main | ||
import Lean.DocString | ||
|
||
namespace Lean | ||
|
||
builtin_initialize | ||
registerBuiltinAttribute { | ||
name := `inheritDoc | ||
descr := "inherit documentation from a specified declaration" | ||
add := fun decl stx kind => do | ||
unless kind == AttributeKind.global do | ||
throwError "invalid `[inheritDoc]` attribute, must be global" | ||
match stx with | ||
| `(attr| inheritDoc $[$id?:ident]?) => | ||
let some id := id? | ||
| throwError "invalid `[inheritDoc]` attribute, could not infer doc source" | ||
let declName ← Elab.resolveGlobalConstNoOverloadWithInfo id | ||
if (← findDocString? (← getEnv) decl).isSome then | ||
logWarningAt id m!"{← mkConstWithLevelParams decl} already has a doc string" | ||
let some doc ← findDocString? (← getEnv) declName | ||
| logWarningAt id m!"{← mkConstWithLevelParams declName} does not have a doc string" | ||
addDocString decl doc | ||
| _ => throwError "invalid `[inheritDoc]` attribute" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters