Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get haddock for makeEffect from the declaration #226

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading