bookshelf/DocGen4/Output/SourceLinker.lean

38 lines
1.2 KiB
Plaintext
Raw Normal View History

2023-05-11 13:27:25 +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
-/
import Lean
namespace DocGen4.Output.SourceLinker
open Lean
/--
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-11-08 01:36:00 +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-05-11 13:27:25 +00:00
return fun module range =>
let parts := module.components.map Name.toString
2023-11-08 01:36:00 +00:00
let path := String.intercalate "/" parts
2023-05-11 13:27:25 +00:00
let root := module.getRoot
2023-11-08 01:36:00 +00:00
let leanHash := Lean.githash
2023-05-11 13:27:25 +00:00
let basic := if root == `Lean root == `Init then
s!"https://github.com/leanprover/lean4/blob/{leanHash}/src/{path}.lean"
2023-09-08 20:19:34 +00:00
else if root == `Lake then
s!"https://github.com/leanprover/lean4/blob/{leanHash}/src/lake/{path}.lean"
2023-05-11 13:27:25 +00:00
else
2023-11-08 01:36:00 +00:00
gitUrl?.get!
2023-05-11 13:27:25 +00:00
match range with
| some range => s!"{basic}#L{range.pos.line}-L{range.endPos.line}"
| none => basic
end DocGen4.Output.SourceLinker