module GHC.Stack.Plus
( callerLocation
, callerFile
, callerLine
, adjustSourceFilePath
)
where
import GHC.Stack
import Safe (tailSafe, lastNote)
adjustSourceFilePath :: FilePath -> FilePath
adjustSourceFilePath = tailSafe . dropWhile (/='/') . drop 1 . dropWhile (/= '/')
callerLocation :: (HasCallStack) => String
callerLocation = callerFile ++ ":" ++ show callerLine
callerFile :: (HasCallStack) => String
callerFile = srcLocFile . callerSrcLoc $ callStack
callerLine :: (HasCallStack) => Int
callerLine = srcLocStartLine . callerSrcLoc $ callStack
callerSrcLoc :: CallStack -> SrcLoc
callerSrcLoc = snd . caller
caller :: CallStack -> (String, SrcLoc)
caller = lastNote "Empty CallStack?!" . getCallStack