2022-05-19 19:56:43 +00:00
|
|
|
|
/-
|
|
|
|
|
Copyright (c) 2022 Henrik Böving. All rights reserved.
|
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
Authors: Henrik Böving
|
|
|
|
|
-/
|
2022-05-19 18:48:26 +00:00
|
|
|
|
import Lean
|
|
|
|
|
|
2023-03-09 20:37:13 +00:00
|
|
|
|
namespace DocGen4.Output.SourceLinker
|
2022-05-19 18:48:26 +00:00
|
|
|
|
|
|
|
|
|
open Lean
|
|
|
|
|
|
2022-05-19 18:52:54 +00:00
|
|
|
|
/--
|
|
|
|
|
Given a lake workspace with all the dependencies as well as the hash of the
|
|
|
|
|
compiler release to work with this provides a function to turn names of
|
|
|
|
|
declarations into (optionally positional) Github URLs.
|
|
|
|
|
-/
|
2023-10-09 07:30:16 +00:00
|
|
|
|
def sourceLinker (gitUrl? : Option String) : IO (Name → Option DeclarationRange → String) := do
|
|
|
|
|
-- TOOD: Refactor this, we don't need to pass in the module into the returned closure
|
|
|
|
|
-- since we have one sourceLinker per module
|
2023-01-01 18:51:01 +00:00
|
|
|
|
return fun module range =>
|
2022-05-19 18:48:26 +00:00
|
|
|
|
let parts := module.components.map Name.toString
|
2023-09-27 07:52:22 +00:00
|
|
|
|
let path := String.intercalate "/" parts
|
2022-05-19 18:48:26 +00:00
|
|
|
|
let root := module.getRoot
|
2023-10-09 07:30:16 +00:00
|
|
|
|
let leanHash := Lean.githash
|
2022-10-05 10:05:58 +00:00
|
|
|
|
let basic := if root == `Lean ∨ root == `Init then
|
2022-05-19 18:48:26 +00:00
|
|
|
|
s!"https://github.com/leanprover/lean4/blob/{leanHash}/src/{path}.lean"
|
2023-08-29 21:45:58 +00:00
|
|
|
|
else if root == `Lake then
|
|
|
|
|
s!"https://github.com/leanprover/lean4/blob/{leanHash}/src/lake/{path}.lean"
|
2022-05-19 18:48:26 +00:00
|
|
|
|
else
|
2023-10-09 07:30:16 +00:00
|
|
|
|
gitUrl?.get!
|
2022-05-19 18:48:26 +00:00
|
|
|
|
|
|
|
|
|
match range with
|
|
|
|
|
| some range => s!"{basic}#L{range.pos.line}-L{range.endPos.line}"
|
|
|
|
|
| none => basic
|
|
|
|
|
|
2023-03-09 20:37:13 +00:00
|
|
|
|
end DocGen4.Output.SourceLinker
|