From 8f931eb928cfe267a73407978be2358ad801ad1c Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Fri, 3 Jul 2015 22:31:52 +0300 Subject: [PATCH] Fix problem with fileModSummary --- Language/Haskell/GhcMod/CaseSplit.hs | 3 ++- Language/Haskell/GhcMod/FileMapping.hs | 9 +++++++++ Language/Haskell/GhcMod/FillSig.hs | 7 ++++--- Language/Haskell/GhcMod/Info.hs | 3 ++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Language/Haskell/GhcMod/CaseSplit.hs b/Language/Haskell/GhcMod/CaseSplit.hs index 77603ca..5d2c414 100644 --- a/Language/Haskell/GhcMod/CaseSplit.hs +++ b/Language/Haskell/GhcMod/CaseSplit.hs @@ -26,6 +26,7 @@ import Language.Haskell.GhcMod.SrcUtils import Language.Haskell.GhcMod.Doc import Language.Haskell.GhcMod.Logging import Language.Haskell.GhcMod.Types +import Language.Haskell.GhcMod.FileMapping (fileModSummaryWithMapping) ---------------------------------------------------------------- -- CASE SPLITTING @@ -51,7 +52,7 @@ splits file lineNo colNo = crdl <- cradle style <- getStyle dflag <- G.getSessionDynFlags - modSum <- Gap.fileModSummary (cradleCurrentDir crdl file) + modSum <- fileModSummaryWithMapping (cradleCurrentDir crdl file) whenFound' opt (getSrcSpanTypeForSplit modSum lineNo colNo) $ \x -> case x of (SplitInfo varName bndLoc (varLoc,varT) _matches) -> do let varName' = showName dflag style varName -- Convert name to string diff --git a/Language/Haskell/GhcMod/FileMapping.hs b/Language/Haskell/GhcMod/FileMapping.hs index bae425e..5d95868 100644 --- a/Language/Haskell/GhcMod/FileMapping.hs +++ b/Language/Haskell/GhcMod/FileMapping.hs @@ -3,6 +3,7 @@ module Language.Haskell.GhcMod.FileMapping , loadMappedFiles , unloadMappedFile , mapFile + , fileModSummaryWithMapping ) where import Language.Haskell.GhcMod.Types @@ -48,3 +49,11 @@ mkMappedTarget tid taoc _ = return $ mkTarget tid taoc Nothing unloadMappedFile :: IOish m => FilePath -> GhcModT m () unloadMappedFile = (delMMappedFile =<<) . getCanonicalFileNameSafe + +fileModSummaryWithMapping :: (IOish m, GmState m, GhcMonad m, GmEnv m) => + FilePath -> m ModSummary +fileModSummaryWithMapping fn = do + mmf <- getCanonicalFileNameSafe fn >>= lookupMMappedFile + case mmf of + Just (RedirectedMapping to) -> fileModSummary to + _ -> fileModSummary fn diff --git a/Language/Haskell/GhcMod/FillSig.hs b/Language/Haskell/GhcMod/FillSig.hs index 1f65f93..02da7a0 100644 --- a/Language/Haskell/GhcMod/FillSig.hs +++ b/Language/Haskell/GhcMod/FillSig.hs @@ -27,6 +27,7 @@ import Language.Haskell.GhcMod.Logging (gmLog) import Language.Haskell.GhcMod.Pretty (showDoc) import Language.Haskell.GhcMod.Doc import Language.Haskell.GhcMod.Types +import Language.Haskell.GhcMod.FileMapping (fileModSummaryWithMapping) import Outputable (PprStyle) import qualified Type as Ty import qualified HsBinds as Ty @@ -76,7 +77,7 @@ sig file lineNo colNo = opt <- options style <- getStyle dflag <- G.getSessionDynFlags - modSum <- Gap.fileModSummary file + modSum <- fileModSummaryWithMapping file whenFound opt (getSignature modSum lineNo colNo) $ \s -> case s of Signature loc names ty -> @@ -345,7 +346,7 @@ refine file lineNo colNo (Expression expr) = opt <- options style <- getStyle dflag <- G.getSessionDynFlags - modSum <- Gap.fileModSummary file + modSum <- fileModSummaryWithMapping file p <- G.parseModule modSum tcm@TypecheckedModule{tm_typechecked_source = tcs} <- G.typecheckModule p ety <- G.exprType expr @@ -422,7 +423,7 @@ auto file lineNo colNo = opt <- options style <- getStyle dflag <- G.getSessionDynFlags - modSum <- Gap.fileModSummary file + modSum <- fileModSummaryWithMapping file p <- G.parseModule modSum tcm@TypecheckedModule { tm_typechecked_source = tcs diff --git a/Language/Haskell/GhcMod/Info.hs b/Language/Haskell/GhcMod/Info.hs index be32635..23e5950 100644 --- a/Language/Haskell/GhcMod/Info.hs +++ b/Language/Haskell/GhcMod/Info.hs @@ -22,6 +22,7 @@ import Language.Haskell.GhcMod.Logging import Language.Haskell.GhcMod.Monad import Language.Haskell.GhcMod.SrcUtils import Language.Haskell.GhcMod.Types +import Language.Haskell.GhcMod.FileMapping (fileModSummaryWithMapping) ---------------------------------------------------------------- @@ -60,7 +61,7 @@ types file lineNo colNo = runGmlT' [Left file] deferErrors $ withContext $ do crdl <- cradle - modSum <- Gap.fileModSummary (cradleCurrentDir crdl file) + modSum <- fileModSummaryWithMapping (cradleCurrentDir crdl file) srcSpanTypes <- getSrcSpanType modSum lineNo colNo dflag <- G.getSessionDynFlags st <- getStyle