Search code examples
yesodtemplate-haskell

How can I see a specific file's generated template haskell code when using yesod


Because of some bad input, a Template Haskell function is generating broken code. How can I apply -ddump-splices to just one file in Yesod?

I know that fixing the bad input is the solution, but debugging that depends on what is being generated by Template Haskell, which I can't see in the error output from what I normally run

stack exec -- yesod devel

I think that the function staticFiles in src/Settings/StaticFiles.hs must be a Template Haskell function. I thought I would give a look into what is generated by that, but I realized I am out of my depth, naively trying stack exec --ghc-options='-ddump-splices' -- yesod devel to no effect.

How can I apply -ddump-splices to just one file in Yesod?

Other higher-level comments on debugging Yesod/Template Haskell are much welcomed.


Solution

  • You can add a pragma to the Haskell file, where you want to render the splices. Like:

    {-# OPTIONS_GHC -ddump-splices #-}
    {-# LANGUAGE TemplateHaskell #-}
    
    import SomeModule(someTHFunction)
    
    foo = $(someTHFunction 14 25)

    When I test this locally, it will only dump slices of template Haskell in the file where this pragma is added, so you can add it to the files where you are interested in the template Haskell implementation, and leave out the other ones.