1
1
mirror of https://github.com/anoma/juvix.git synced 2025-01-05 22:46:08 +03:00

Generate documentation for local modules in the html backend (#2326)

![image](https://github.com/anoma/juvix/assets/5511599/bffc47d1-660e-484a-8bca-e61fc7e15cd9)

Local modules are shown as regular statements, with their definitions
displayed nested
This commit is contained in:
Jan Mas Rovira 2023-08-31 17:31:19 +02:00 committed by GitHub
parent 3c5304ff9d
commit f463aeed0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 12 deletions

View File

@ -318,7 +318,7 @@ goTopModule cs m = do
content :: Sem s Html
content = do
preface' <- docPreface
interface' <- interface
interface' <- moduleInterface
return
$ Html.div
! Attr.id "content"
@ -368,8 +368,8 @@ goTopModule cs m = do
! Attr.id "module-header"
$ (p ! Attr.class_ "caption" $ toHtml (prettyText tmp))
interface :: Sem s Html
interface = do
moduleInterface :: Sem s Html
moduleInterface = do
sigs' <- mconcatMapM goStatement (m ^. moduleBody)
return
$ Html.div
@ -429,7 +429,7 @@ goStatement = \case
StatementFunctionDef t -> goFunctionDef t
StatementSyntax s -> goSyntax s
StatementImport {} -> mempty
StatementModule {} -> mempty -- TODO handle local modules
StatementModule m -> goLocalModule m
StatementProjectionDef {} -> mempty
where
goSyntax :: SyntaxDef 'Scoped -> Sem r Html
@ -486,6 +486,19 @@ goAlias def = do
sig' <- ppCodeHtml defaultOptions def
defHeader (def ^. aliasDefName) sig' Nothing
-- | local modules generated by inductive types should not show up.
goLocalModule :: forall r. (Members '[Reader HtmlOptions, Reader NormalizedTable] r) => Module 'Scoped 'ModuleLocal -> Sem r Html
goLocalModule def = fmap (fromMaybe mempty) . runFail $ do
failWhen (def ^. moduleInductive)
sig' <- ppHelper (ppModuleHeader def)
header' <- defHeader (def ^. modulePath) sig' (def ^. moduleDoc)
body' <-
( Html.div
! Attr.class_ "subs"
)
<$> mconcatMap goStatement (def ^. moduleBody)
return (header' <> body')
goOpen :: forall r. (Members '[Reader HtmlOptions] r) => OpenModule 'Scoped -> Sem r Html
goOpen op
| Public <- op ^. openPublic = noDefHeader <$> ppCodeHtml defaultOptions op

View File

@ -336,13 +336,19 @@ withNameIdSuffix nid a = do
instance PrettyPrint S.NameId where
ppCode (S.NameId k) = noLoc (pretty k)
ppModuleHeader :: (SingI t, SingI s) => PrettyPrinting (Module s t)
ppModuleHeader Module {..} = do
let modulePath' = ppModulePathType _modulePath
ppCode _moduleKw
<+> modulePath'
instance (SingI t, SingI s) => PrettyPrint (Module s t) where
ppCode :: forall r. (Members '[ExactPrint, Reader Options] r) => Module s t -> Sem r ()
ppCode Module {..} = do
ppCode m@Module {..} = do
let moduleBody' = localIndent (ppStatements _moduleBody)
modulePath' = ppModulePathType _modulePath
moduleDoc' = whenJust _moduleDoc ppCode
modulePragmas' = whenJust _modulePragmas ppCode
header' = ppModuleHeader m
body'
| null _moduleBody = ensureEmptyLine
| otherwise =
@ -351,12 +357,11 @@ instance (SingI t, SingI s) => PrettyPrint (Module s t) where
<> line
moduleDoc'
<> modulePragmas'
<> ppCode _moduleKw
<+> modulePath'
<> ppCode Kw.delimSemicolon
<> line
<> body'
<> ending
<> header'
<> ppCode Kw.delimSemicolon
<> line
<> body'
<> ending
where
topSpace :: Sem r ()
topSpace = case sing :: SModuleIsTop t of