feat: more declaration data as JSON
parent
e09280bb3c
commit
718b182a31
|
@ -128,16 +128,20 @@ def htmlOutputIndex (baseConfig : SiteBaseContext) : IO Unit := do
|
||||||
htmlOutputSetup baseConfig
|
htmlOutputSetup baseConfig
|
||||||
|
|
||||||
let mut index : JsonIndex := {}
|
let mut index : JsonIndex := {}
|
||||||
|
let mut headerIndex : JsonHeaderIndex := {}
|
||||||
for entry in ← System.FilePath.readDir declarationsBasePath do
|
for entry in ← System.FilePath.readDir declarationsBasePath do
|
||||||
if entry.fileName.startsWith "declaration-data-" && entry.fileName.endsWith ".bmp" then
|
if entry.fileName.startsWith "declaration-data-" && entry.fileName.endsWith ".bmp" then
|
||||||
let fileContent ← FS.readFile entry.path
|
let fileContent ← FS.readFile entry.path
|
||||||
let .ok jsonContent := Json.parse fileContent | unreachable!
|
let .ok jsonContent := Json.parse fileContent | unreachable!
|
||||||
let .ok (module : JsonModule) := fromJson? jsonContent | unreachable!
|
let .ok (module : JsonModule) := fromJson? jsonContent | unreachable!
|
||||||
index := index.addModule module |>.run baseConfig
|
index := index.addModule module |>.run baseConfig
|
||||||
|
headerIndex := headerIndex.addModule module
|
||||||
|
|
||||||
let finalJson := toJson index
|
let finalJson := toJson index
|
||||||
|
let finalHeaderJson := toJson headerIndex
|
||||||
-- The root JSON for find
|
-- The root JSON for find
|
||||||
FS.writeFile (declarationsBasePath / "declaration-data.bmp") finalJson.compress
|
FS.writeFile (declarationsBasePath / "declaration-data.bmp") finalJson.compress
|
||||||
|
FS.writeFile (declarationsBasePath / "header-data.bmp") finalHeaderJson.compress
|
||||||
|
|
||||||
/--
|
/--
|
||||||
The main entrypoint for outputting the documentation HTML based on an
|
The main entrypoint for outputting the documentation HTML based on an
|
||||||
|
|
|
@ -1,18 +1,25 @@
|
||||||
import Lean
|
import Lean
|
||||||
import DocGen4.Process
|
import DocGen4.Process
|
||||||
import DocGen4.Output.Base
|
import DocGen4.Output.Base
|
||||||
|
import DocGen4.Output.Module
|
||||||
import Lean.Data.RBMap
|
import Lean.Data.RBMap
|
||||||
|
|
||||||
namespace DocGen4.Output
|
namespace DocGen4.Output
|
||||||
|
|
||||||
open Lean
|
open Lean
|
||||||
|
|
||||||
structure JsonDeclaration where
|
structure JsonDeclarationInfo where
|
||||||
name : String
|
name : String
|
||||||
kind : String
|
kind : String
|
||||||
doc : String
|
doc : String
|
||||||
docLink : String
|
docLink : String
|
||||||
sourceLink : String
|
sourceLink : String
|
||||||
|
line : Nat
|
||||||
|
deriving FromJson, ToJson
|
||||||
|
|
||||||
|
structure JsonDeclaration where
|
||||||
|
info : JsonDeclarationInfo
|
||||||
|
header : String
|
||||||
deriving FromJson, ToJson
|
deriving FromJson, ToJson
|
||||||
|
|
||||||
structure JsonInstance where
|
structure JsonInstance where
|
||||||
|
@ -28,13 +35,19 @@ structure JsonModule where
|
||||||
imports : Array String
|
imports : Array String
|
||||||
deriving FromJson, ToJson
|
deriving FromJson, ToJson
|
||||||
|
|
||||||
|
structure JsonHeaderIndex where
|
||||||
|
headers : List (String × String) := []
|
||||||
|
|
||||||
structure JsonIndex where
|
structure JsonIndex where
|
||||||
declarations : List (String × JsonDeclaration) := []
|
declarations : List (String × JsonDeclarationInfo) := []
|
||||||
instances : HashMap String (RBTree String Ord.compare) := .empty
|
instances : HashMap String (RBTree String Ord.compare) := .empty
|
||||||
importedBy : HashMap String (Array String) := .empty
|
importedBy : HashMap String (Array String) := .empty
|
||||||
modules : List (String × String) := []
|
modules : List (String × String) := []
|
||||||
instancesFor : HashMap String (RBTree String Ord.compare) := .empty
|
instancesFor : HashMap String (RBTree String Ord.compare) := .empty
|
||||||
|
|
||||||
|
instance : ToJson JsonHeaderIndex where
|
||||||
|
toJson idx := Json.mkObj <| idx.headers.map (fun (k, v) => (k, toJson v))
|
||||||
|
|
||||||
instance : ToJson JsonIndex where
|
instance : ToJson JsonIndex where
|
||||||
toJson idx := Id.run do
|
toJson idx := Id.run do
|
||||||
let jsonDecls := Json.mkObj <| idx.declarations.map (fun (k, v) => (k, toJson v))
|
let jsonDecls := Json.mkObj <| idx.declarations.map (fun (k, v) => (k, toJson v))
|
||||||
|
@ -51,10 +64,14 @@ instance : ToJson JsonIndex where
|
||||||
]
|
]
|
||||||
return finalJson
|
return finalJson
|
||||||
|
|
||||||
|
def JsonHeaderIndex.addModule (index : JsonHeaderIndex) (module : JsonModule) : JsonHeaderIndex :=
|
||||||
|
let merge idx decl := { idx with headers := (decl.info.name, decl.header) :: idx.headers }
|
||||||
|
module.declarations.foldl merge index
|
||||||
|
|
||||||
def JsonIndex.addModule (index : JsonIndex) (module : JsonModule) : BaseHtmlM JsonIndex := do
|
def JsonIndex.addModule (index : JsonIndex) (module : JsonModule) : BaseHtmlM JsonIndex := do
|
||||||
let mut index := index
|
let mut index := index
|
||||||
let newModule := (module.name, ← moduleNameToLink (String.toName module.name))
|
let newModule := (module.name, ← moduleNameToLink (String.toName module.name))
|
||||||
let newDecls := module.declarations.map (fun d => (d.name, d))
|
let newDecls := module.declarations.map (fun d => (d.info.name, d.info))
|
||||||
index := { index with
|
index := { index with
|
||||||
modules := newModule :: index.modules
|
modules := newModule :: index.modules
|
||||||
declarations := newDecls ++ index.declarations
|
declarations := newDecls ++ index.declarations
|
||||||
|
@ -81,7 +98,10 @@ def DocInfo.toJson (module : Name) (info : Process.DocInfo) : HtmlM JsonDeclarat
|
||||||
let doc := info.getDocString.getD ""
|
let doc := info.getDocString.getD ""
|
||||||
let docLink ← declNameToLink info.getName
|
let docLink ← declNameToLink info.getName
|
||||||
let sourceLink ← getSourceUrl module info.getDeclarationRange
|
let sourceLink ← getSourceUrl module info.getDeclarationRange
|
||||||
return { name, kind, doc, docLink, sourceLink }
|
let line := info.getDeclarationRange.pos.line
|
||||||
|
let header := (← docInfoHeader info).toString
|
||||||
|
let info := { name, kind, doc, docLink, sourceLink, line }
|
||||||
|
return { info, header }
|
||||||
|
|
||||||
def Process.Module.toJson (module : Process.Module) : HtmlM Json := do
|
def Process.Module.toJson (module : Process.Module) : HtmlM Json := do
|
||||||
let mut jsonDecls := []
|
let mut jsonDecls := []
|
||||||
|
|
Loading…
Reference in New Issue