Skip to content

Commit

Permalink
fix: label functions with with their servers
Browse files Browse the repository at this point in the history
  • Loading branch information
Endrit committed Apr 19, 2024
1 parent 91c2877 commit 5817025
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Pinch/Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -446,27 +446,27 @@ gService s = do
settings <- asks cSettings
(nms, tys, handlers, calls, tyDecls) <- unzip5 <$> traverse gFunction (serviceFunctions s)

let (additionalImports, baseService) = case serviceExtends s of
let (additionalImports, baseService, baseFunction) = case serviceExtends s of
Just baseServiceIdentifier -> do
case T.splitOn "." baseServiceIdentifier of
[importSource, baseServiceName] -> do
let importModule = (getModuleName settings headers $ T.unpack importSource) <> ".Server"
([importModule], [("baseServer", H.TyCon $ importModule <> "." <> baseServiceName)])
_ -> ([], [])
Nothing -> ([], [])
([importModule], [("baseServer", H.TyCon $ importModule <> "." <> baseServiceName)], ".functions_" <> baseServiceName)
_ -> ([], [], "")
Nothing -> ([], [], "")
let extensionFunction = case additionalImports of
[] -> ""
imports -> head imports <> ".functions (baseServer server) `Data.HashMap.Strict.union` "
imports -> head imports <> baseFunction <> " (baseServer server) `Data.HashMap.Strict.union` "
let serverDecls =
[ H.DataDecl serviceTyName [ H.RecConDecl serviceConName $ baseService <> zip nms tys ] []
, H.TypeSigDecl
"functions"
("functions_" <> serviceConName)
( H.TyLam
[H.TyCon serviceConName]
(H.TyCon "Data.HashMap.Strict.HashMap Data.Text.Text Pinch.Server.Handler")
)
, H.FunBind
[ H.Match "functions" [H.PVar "server"]
[ H.Match ("functions_" <> serviceConName) [H.PVar "server"]
( H.EApp (H.EVar (extensionFunction <> "Data.HashMap.Strict.fromList")) [ H.EList handlers ] )
]
, H.TypeSigDecl (prefix <> "_mkServer") (H.TyLam [H.TyCon serviceConName] (H.TyCon "Pinch.Server.ThriftServer"))
Expand All @@ -475,7 +475,7 @@ gService s = do
( H.EApp "Pinch.Server.createServer"
[ (H.ELam ["nm"]
(H.EApp "Data.HashMap.Strict.lookup"
[ "nm", "functions server" ]
[ "nm", H.EVar $ "functions_" <> serviceConName <> " server" ]
)
)
]
Expand Down

0 comments on commit 5817025

Please sign in to comment.