Skip to content

Commit

Permalink
Get haddock for makeEffect from the declaration (#226)
Browse files Browse the repository at this point in the history
Fixes #225
  • Loading branch information
michaelpj authored Jul 3, 2024
1 parent 0d334be commit e7adeef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 11 additions & 3 deletions effectful-th/src/Effectful/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ import Effectful.Dispatch.Dynamic
-- lowercase or removes the @:@ symbol in case of operators. Any fixity
-- annotations defined for the constructors are preserved for the corresponding
-- definitions.
--
-- If the constructor declaration has Haddock, then this is reused for the
-- sending functions, otherwise a simple placeholder is used.
makeEffect :: Name -> Q [Dec]
makeEffect = makeEffectImpl True

Expand Down Expand Up @@ -246,10 +249,15 @@ makeTyp esVar substM resTy = \case

withHaddock :: Name -> [Dec] -> Q [Dec]
#if MIN_VERSION_template_haskell(2,18,0)
withHaddock name dec = withDecsDoc
("Perform the operation '" ++ nameBase name ++ "'.") (pure dec)
withHaddock name decs = do
existingHaddock <- getDoc (DeclDoc name)
let newDoc =
case existingHaddock of
Just doc -> doc
Nothing -> "Perform the operation '" ++ nameBase name ++ "'."
withDecsDoc newDoc (pure decs)
#else
withHaddock _ dec = pure dec
withHaddock _ decs = pure decs
#endif

checkRequiredExtensions :: Q ()
Expand Down
2 changes: 2 additions & 0 deletions effectful-th/tests/ThTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ main = pure () -- only compilation tests
data SimpleADT (m :: Type -> Type) (a :: Type)
= SimpleADTC1 Int
| SimpleADTC2 String
-- ^ This one does the second thing

-- Test generation of fixity information.
infixl 1 `SimpleADTC1`
Expand All @@ -40,6 +41,7 @@ makeEffect ''ADTSyntax3

data GADTSyntax :: Effect where
GADTSyntaxC1 :: Int -> GADTSyntax m Int
-- | I am documented
GADTSyntaxC2 :: String -> GADTSyntax m String
GADTSyntaxC3 :: IOE :> es => Bool -> GADTSyntax (Eff es) a

Expand Down

0 comments on commit e7adeef

Please sign in to comment.