From 63f05508b8cc72e409e130378d1b47fd96c34870 Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Sun, 20 Dec 2015 13:45:51 +0300 Subject: [PATCH] FileMapping library docs --- Language/Haskell/GhcMod/FileMapping.hs | 35 +++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/Language/Haskell/GhcMod/FileMapping.hs b/Language/Haskell/GhcMod/FileMapping.hs index 1e7e0c1..1806017 100644 --- a/Language/Haskell/GhcMod/FileMapping.hs +++ b/Language/Haskell/GhcMod/FileMapping.hs @@ -20,10 +20,30 @@ import Control.Monad.Trans.Maybe import GHC import Control.Monad -loadMappedFile :: IOish m => FilePath -> FilePath -> GhcModT m () +{- | maps 'FilePath', given as first argument to take source from +'FilePath' given as second argument. Works exactly the same as +first form of `--map-file` CLI option. + +\'from\' can be either full path, or path relative to project root. +\'to\' has to be either relative to project root, or full path (preferred) +-} +loadMappedFile :: IOish m + => FilePath -- ^ \'from\', file that will be mapped + -> FilePath -- ^ \'to\', file to take source from + -> GhcModT m () loadMappedFile from to = loadMappedFile' from to False -loadMappedFileSource :: IOish m => FilePath -> String -> GhcModT m () +{- | +maps 'FilePath', given as first argument to have source as given +by second argument. + +\'from\' may or may not exist, and should be either full path, +or relative to project root. +-} +loadMappedFileSource :: IOish m + => FilePath -- ^ \'from\', file that will be mapped + -> String -- ^ \'src\', source + -> GhcModT m () loadMappedFileSource from src = do tmpdir <- cradleTempDir `fmap` cradle to <- liftIO $ do @@ -59,7 +79,16 @@ mkMappedTarget _ _ taoc (Just to) = return $ mkTarget (TargetFile (fmPath to) Nothing) taoc Nothing mkMappedTarget _ tid taoc _ = return $ mkTarget tid taoc Nothing -unloadMappedFile :: IOish m => FilePath -> GhcModT m () +{-| +unloads previously mapped file \'file\', so that it's no longer mapped, +and removes any temporary files created when file was +mapped. + +\'file\' should be either full path, or relative to project root. +-} +unloadMappedFile :: IOish m + => FilePath -- ^ \'file\', file to unmap + -> GhcModT m () unloadMappedFile = getCanonicalFileNameSafe >=> unloadMappedFile' unloadMappedFile' :: IOish m => FilePath -> GhcModT m ()