Skip to content

Commit

Permalink
feat: Respect srcDir configuration in lake
Browse files Browse the repository at this point in the history
  • Loading branch information
hargoniX committed Sep 27, 2023
1 parent e1bd706 commit 649e779
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions DocGen4/Output/SourceLinker.lean
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def getProjectCommit (directory : System.FilePath := "." ) : IO String := do
throw <| IO.userError <| s!"git exited with code {out.exitCode} while looking for the current commit in {directory}"
return out.stdout.trimRight

def modulePath (ws : Lake.Workspace) (module : Name) : Option (Lake.Package × Lake.LeanLibConfig) := do
let pkg ← ws.packages.find? (·.isLocalModule module)
let libConfig ← pkg.leanLibConfigs.toArray.find? (·.isLocalModule module)
return (pkg, libConfig)

/--
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
Expand All @@ -82,17 +87,20 @@ def sourceLinker (ws : Lake.Workspace) : IO (Name → Option DeclarationRange

return fun module range =>
let parts := module.components.map Name.toString
let path := (parts.intersperse "/").foldl (· ++ ·) ""
let path := String.intercalate "/" parts
let root := module.getRoot
let basic := if root == `Lean ∨ root == `Init then
s!"https://github.com/leanprover/lean4/blob/{leanHash}/src/{path}.lean"
else if root == `Lake then
s!"https://github.com/leanprover/lean4/blob/{leanHash}/src/lake/{path}.lean"
else
match ws.packages.find? (·.isLocalModule module) with
| some pkg =>
match modulePath ws module with
| some (pkg, lib) =>
match gitMap.find? pkg.name with
| some (baseUrl, commit) => s!"{baseUrl}/blob/{commit}/{path}.lean"
| some (baseUrl, commit) =>
let libPath := pkg.config.srcDir / lib.srcDir
let basePath := String.intercalate "/" (libPath.components.filter (· != "."))
s!"{baseUrl}/blob/{commit}/{basePath}/{path}.lean"
| none => "https://example.com"
| none => "https://example.com"

Expand Down

0 comments on commit 649e779

Please sign in to comment.