module Plutarch.Internal.PrettyStack (prettyStack) where

import Data.Text (Text, pack)
import GHC.Stack (CallStack, SrcLoc (srcLocFile, srcLocStartLine), getCallStack)

prettyStack :: Text -> CallStack -> Text
prettyStack :: Text -> CallStack -> Text
prettyStack Text
prefix CallStack
cs = case CallStack -> [(String, SrcLoc)]
getCallStack CallStack
cs of
  ((String
_, SrcLoc
loc) : [(String, SrcLoc)]
_) ->
    let loc' :: Text
loc' = String -> Text
pack SrcLoc
loc.srcLocFile forall a. Semigroup a => a -> a -> a
<> Text
":" forall a. Semigroup a => a -> a -> a
<> String -> Text
pack (forall a. Show a => a -> String
show SrcLoc
loc.srcLocStartLine)
     in Text
prefix forall a. Semigroup a => a -> a -> a
<> Text
"[" forall a. Semigroup a => a -> a -> a
<> Text
loc' forall a. Semigroup a => a -> a -> a
<> Text
"]"
  [(String, SrcLoc)]
_ -> Text
"<missing call stack>"