diff --git a/DocGen4/Load.lean b/DocGen4/Load.lean index c579837..7a6dec3 100644 --- a/DocGen4/Load.lean +++ b/DocGen4/Load.lean @@ -29,10 +29,14 @@ def load (task : Process.AnalyzeTask) : IO (Process.AnalyzerResult × Hierarchy) let config := { -- TODO: parameterize maxHeartbeats maxHeartbeats := 100000000, - options := ⟨[(`pp.tagAppFns, true)]⟩, + options := ⟨[ + (`pp.tagAppFns, true), + (`pp.funBinderTypes, true) + ]⟩, -- TODO: Figure out whether this could cause some bugs fileName := default, fileMap := default, + catchRuntimeEx := true, } Prod.fst <$> Meta.MetaM.toIO (Process.process task) config { env := env } {} {} diff --git a/DocGen4/Output/Base.lean b/DocGen4/Output/Base.lean index 4b22db6..1d2c7e1 100644 --- a/DocGen4/Output/Base.lean +++ b/DocGen4/Output/Base.lean @@ -11,7 +11,7 @@ namespace DocGen4.Output open scoped DocGen4.Jsx open Lean System Widget Elab Process -def basePath := FilePath.mk "." / "build" / "doc" +def basePath := FilePath.mk "." / ".lake" / "build" / "doc" def srcBasePath := basePath / "src" def declarationsBasePath := basePath / "declarations" @@ -105,6 +105,13 @@ def moduleNameExtToLink (n : NameExt) : BaseHtmlM String := do let parts := n.name.components.map Name.toString return (← getRoot) ++ (parts.intersperse "/").foldl (· ++ ·) "" ++ "." ++ n.ext.toString +/-- +Returns the doc-gen4 link to a module name. +-/ +def moduleNameToLink (n : Name) : BaseHtmlM String := do + let parts := n.components.map Name.toString + return (← getRoot) ++ (parts.intersperse "/").foldl (· ++ ·) "" ++ ".html" + /-- Returns the doc-gen4 link to a module name. -/ diff --git a/DocGen4/Output/Inductive.lean b/DocGen4/Output/Inductive.lean index fde7d40..3d6eaf3 100644 --- a/DocGen4/Output/Inductive.lean +++ b/DocGen4/Output/Inductive.lean @@ -10,9 +10,9 @@ open Lean def instancesForToHtml (typeName : Name) : BaseHtmlM Html := do pure -
+
Instances For - +
def ctorToHtml (c : Process.NameInfo) : HtmlM Html := do diff --git a/DocGen4/Output/Module.lean b/DocGen4/Output/Module.lean index b14b6da..df6ac05 100644 --- a/DocGen4/Output/Module.lean +++ b/DocGen4/Output/Module.lean @@ -133,8 +133,8 @@ def docInfoToHtml (module : Name) (doc : DocInfo) : HtmlM Html := do [leanInkHtml] [attrsHtml] {← docInfoHeader doc} - [docInfoHtml] [docStringHtml] + [docInfoHtml] [extraInfoHtml] diff --git a/DocGen4/Output/ToJson.lean b/DocGen4/Output/ToJson.lean index ad6a59c..2843d05 100644 --- a/DocGen4/Output/ToJson.lean +++ b/DocGen4/Output/ToJson.lean @@ -43,11 +43,15 @@ structure JsonIndexedDeclarationInfo where docLink : String deriving FromJson, ToJson +structure JsonIndexedModule where + importedBy : Array String + url : String + deriving FromJson, ToJson + structure JsonIndex where declarations : List (String × JsonIndexedDeclarationInfo) := [] instances : HashMap String (RBTree String Ord.compare) := .empty - importedBy : HashMap String (Array String) := .empty - modules : List (String × String) := [] + modules : HashMap String JsonIndexedModule := {} instancesFor : HashMap String (RBTree String Ord.compare) := .empty instance : ToJson JsonHeaderIndex where @@ -57,13 +61,11 @@ instance : ToJson JsonIndex where toJson idx := Id.run do let jsonDecls := Json.mkObj <| idx.declarations.map (fun (k, v) => (k, toJson v)) let jsonInstances := Json.mkObj <| idx.instances.toList.map (fun (k, v) => (k, toJson v.toArray)) - let jsonImportedBy := Json.mkObj <| idx.importedBy.toList.map (fun (k, v) => (k, toJson v)) - let jsonModules := Json.mkObj <| idx.modules.map (fun (k, v) => (k, toJson v)) + let jsonModules := Json.mkObj <| idx.modules.toList.map (fun (k, v) => (k, toJson v)) let jsonInstancesFor := Json.mkObj <| idx.instancesFor.toList.map (fun (k, v) => (k, toJson v.toArray)) let finalJson := Json.mkObj [ ("declarations", jsonDecls), ("instances", jsonInstances), - ("importedBy", jsonImportedBy), ("modules", jsonModules), ("instancesFor", jsonInstancesFor) ] @@ -75,15 +77,14 @@ def JsonHeaderIndex.addModule (index : JsonHeaderIndex) (module : JsonModule) : def JsonIndex.addModule (index : JsonIndex) (module : JsonModule) : BaseHtmlM JsonIndex := do let mut index := index - let newModule := (module.name, ← moduleNameToHtmlLink (String.toName module.name)) let newDecls := module.declarations.map (fun d => (d.info.name, { kind := d.info.kind, docLink := d.info.docLink, })) index := { index with - modules := newModule :: index.modules declarations := newDecls ++ index.declarations } + -- TODO: In theory one could sort instances and imports by name and batch the writes for inst in module.instances do let mut insts := index.instances.findD inst.className {} @@ -94,10 +95,26 @@ def JsonIndex.addModule (index : JsonIndex) (module : JsonModule) : BaseHtmlM Js instsFor := instsFor.insert inst.name index := { index with instancesFor := index.instancesFor.insert typeName instsFor } + -- TODO: dedup + if index.modules.find? module.name |>.isNone then + let moduleLink <- moduleNameToLink (String.toName module.name) + let indexedModule := { url := moduleLink, importedBy := #[] } + index := { index with modules := index.modules.insert module.name indexedModule } + for imp in module.imports do - let mut impBy := index.importedBy.findD imp #[] - impBy := impBy.push module.name - index := { index with importedBy := index.importedBy.insert imp impBy } + let indexedImp ← + match index.modules.find? imp with + | some i => pure i + | none => + let impLink ← moduleNameToLink (String.toName imp) + let indexedModule := { url := impLink, importedBy := #[] } + pure indexedModule + index := { index with + modules := + index.modules.insert + imp + { indexedImp with importedBy := indexedImp.importedBy.push module.name } + } return index def DocInfo.toJson (module : Name) (info : Process.DocInfo) : HtmlM JsonDeclaration := do diff --git a/DocGen4/Process/Analyze.lean b/DocGen4/Process/Analyze.lean index f3f1910..3e6600d 100644 --- a/DocGen4/Process/Analyze.lean +++ b/DocGen4/Process/Analyze.lean @@ -126,7 +126,8 @@ def process (task : AnalyzeTask) : MetaM (AnalyzerResult × Hierarchy) := do maxHeartbeats := 5000000, options := ← getOptions, fileName := ← getFileName, - fileMap := ← getFileMap + fileMap := ← getFileMap, + catchRuntimeEx := true, } let analysis ← Prod.fst <$> Meta.MetaM.toIO (DocInfo.ofConstant (name, cinfo)) config { env := env } {} {} if let some dinfo := analysis then diff --git a/DocGen4/Process/DefinitionInfo.lean b/DocGen4/Process/DefinitionInfo.lean index c6255d5..6f75b7c 100644 --- a/DocGen4/Process/DefinitionInfo.lean +++ b/DocGen4/Process/DefinitionInfo.lean @@ -36,8 +36,10 @@ def DefinitionInfo.ofDefinitionVal (v : DefinitionVal) : MetaM DefinitionInfo := let info ← Info.ofConstantVal v.toConstantVal let isUnsafe := v.safety == DefinitionSafety.unsafe let isNonComputable := isNoncomputable (← getEnv) v.name + try - let eqs? ← getEqnsFor? v.name + let eqs? ← getEqnsFor? v.name + match eqs? with | some eqs => let equations ← eqs.mapM processEq diff --git a/static/declaration-data.js b/static/declaration-data.js index 378c9bf..a20c494 100644 --- a/static/declaration-data.js +++ b/static/declaration-data.js @@ -128,7 +128,7 @@ export class DeclarationDataCenter { * @returns {Array} */ moduleImportedBy(moduleName) { - return this.declarationData.importedBy[moduleName]; + return this.declarationData.modules[moduleName].importedBy; } /** @@ -136,7 +136,7 @@ export class DeclarationDataCenter { * @returns {String} */ moduleNameToLink(moduleName) { - return this.declarationData.modules[moduleName]; + return this.declarationData.modules[moduleName].url; } } @@ -269,4 +269,4 @@ async function fetchCachedDeclarationData() { reject(new Error(`fail to store declaration data`)); }; }); -} \ No newline at end of file +} diff --git a/static/instances.js b/static/instances.js index fa73c5c..9389a29 100644 --- a/static/instances.js +++ b/static/instances.js @@ -26,11 +26,16 @@ async function annotateInstancesFor() { for (const instanceForList of instanceForLists) { const typeName = instanceForList.id.slice("instances-for-list-".length); const instances = dataCenter.instancesForType(typeName); - var innerHTML = ""; - for(var instance of instances) { - const instanceLink = dataCenter.declNameToLink(instance); - innerHTML += `
  • ${instance}
  • ` + if (instances.length == 0) { + instanceForList.remove(); + } else { + var innerHTML = ""; + for(var instance of instances) { + const instanceLink = dataCenter.declNameToLink(instance); + innerHTML += `
  • ${instance}
  • `; + } + const instanceEnum = instanceForList.querySelector(".instances-for-enum"); + instanceEnum.innerHTML = innerHTML; } - instanceForList.innerHTML = innerHTML; } } diff --git a/static/style.css b/static/style.css index 5b5ea8e..4c6b2f8 100644 --- a/static/style.css +++ b/static/style.css @@ -1,15 +1,20 @@ -@import url('https://fonts.googleapis.com/css2?family=Merriweather&family=Open+Sans&family=Source+Code+Pro&family=Source+Code+Pro:wght@600&display=swap'); +@import url('https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css'); +@import url('https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.051/juliamono.css'); * { box-sizing: border-box; } body { - font-family: 'Open Sans', sans-serif; + font-size: 17px; + font-variant-ligatures: none; + font-family: 'Lato Medium'; color: var(--text-color); background: var(--body-bg); } +input, select, textarea, button{font-family:inherit;} + a { color: var(--link-color); } @@ -19,7 +24,8 @@ a.pdf { } h1, h2, h3, h4, h5, h6 { - font-family: 'Merriweather', serif; + font-family: 'Lato Medium'; + font-size: 17px; } body { line-height: 1.5; } @@ -678,8 +684,10 @@ main h2, main h3, main h4, main h5, main h6 { } .imports li, code, .decl_header, .attributes, .structure_field_info, - .constructor, .instances li, .equation, .result_link, .structure_ext_ctor { - font-family: 'Source Code Pro', monospace; +.constructor, .instances li, .instances-for-list li, .equation, +.structure_ext_ctor { + font-size: 16px; + font-family: 'JuliaMono', monospace; } pre { @@ -709,12 +717,14 @@ pre code { padding: 0 0; } .inductive_ctor_doc { text-indent: 2ex; - font-family: 'Open Sans', sans-serif; + font-family: 'Lato Medium'; + font-size: 17px; } .structure_field_doc { text-indent: 0; - font-family: 'Open Sans', sans-serif; + font-family: 'Lato Medium'; + font-size: 17px; } .structure_ext_fields { @@ -812,4 +822,4 @@ a:hover { padding-top: 2em; margin-top: 2em; margin-bottom: 2em; -} \ No newline at end of file +}