Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
Save source files with HIE files
Browse files Browse the repository at this point in the history
  • Loading branch information
fendor committed Sep 8, 2020
1 parent 9ae5134 commit e2cb33d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import Control.Monad.Extra
import Control.Monad.Except
import Control.Monad.Trans.Except
import Data.Bifunctor (first, second)
import qualified Data.ByteString as BS
import qualified Data.Text as T
import Data.IORef
import Data.List.Extra
Expand Down Expand Up @@ -280,13 +281,13 @@ atomicFileWrite targetPath write = do
(tempFilePath, cleanUp) <- newTempFileWithin dir
(write tempFilePath >> renameFile tempFilePath targetPath) `onException` cleanUp

generateAndWriteHieFile :: HscEnv -> TypecheckedModule -> IO [FileDiagnostic]
generateAndWriteHieFile hscEnv tcm =
generateAndWriteHieFile :: HscEnv -> TypecheckedModule -> BS.ByteString -> IO [FileDiagnostic]
generateAndWriteHieFile hscEnv tcm source =
handleGenerationErrors dflags "extended interface generation" $ do
case tm_renamed_source tcm of
Just rnsrc -> do
hf <- runHsc hscEnv $
GHC.mkHieFile mod_summary (fst $ tm_internals_ tcm) rnsrc ""
GHC.mkHieFile mod_summary (fst $ tm_internals_ tcm) rnsrc source
atomicFileWrite targetPath $ flip GHC.writeHieFile hf
_ ->
return ()
Expand Down
20 changes: 15 additions & 5 deletions src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import Data.IntMap.Strict (IntMap)
import Data.List
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Development.IDE.GHC.Error
import Development.Shake hiding (Diagnostic)
import Development.IDE.Core.RuleTypes
Expand Down Expand Up @@ -188,11 +189,18 @@ getHomeHieFile f = do
wait <- lift $ delayedAction $ mkDelayedAction "OutOfDateHie" L.Info $ do
hsc <- hscEnv <$> use_ GhcSession f
pm <- use_ GetParsedModule f
typeCheckRuleDefinition hsc pm DoGenerateInterfaceFiles
source <- getSourceFileSource f
typeCheckRuleDefinition hsc pm DoGenerateInterfaceFiles (Just source)
_ <- MaybeT $ liftIO $ timeout 1 wait
ncu <- mkUpdater
liftIO $ loadHieFile ncu hie_f

getSourceFileSource :: NormalizedFilePath -> Action BS.ByteString
getSourceFileSource nfp = do
(_, msource) <- getFileContents nfp
case msource of
Nothing -> liftIO $ BS.readFile (fromNormalizedFilePath nfp)
Just source -> pure $ T.encodeUtf8 source

getPackageHieFile :: ShakeExtras
-> Module -- ^ Package Module to load .hie file for
Expand Down Expand Up @@ -519,7 +527,7 @@ typeCheckRule = define $ \TypeCheck file -> do
hsc <- hscEnv <$> use_ GhcSessionDeps file
-- do not generate interface files as this rule is called
-- for files of interest on every keystroke
typeCheckRuleDefinition hsc pm SkipGenerationOfInterfaceFiles
typeCheckRuleDefinition hsc pm SkipGenerationOfInterfaceFiles Nothing

knownFilesRule :: Rules ()
knownFilesRule = defineEarlyCutOffNoFile $ \GetKnownFiles -> do
Expand All @@ -546,8 +554,9 @@ typeCheckRuleDefinition
:: HscEnv
-> ParsedModule
-> GenerateInterfaceFiles -- ^ Should generate .hi and .hie files ?
-> Maybe BS.ByteString
-> Action (IdeResult TcModuleResult)
typeCheckRuleDefinition hsc pm generateArtifacts = do
typeCheckRuleDefinition hsc pm generateArtifacts source = do
setPriority priorityTypeCheck
IdeOptions { optDefer = defer } <- getIdeOptions

Expand All @@ -560,7 +569,7 @@ typeCheckRuleDefinition hsc pm generateArtifacts = do
-- type errors, as we won't get proper diagnostics if we load these from
-- disk
, not $ tmrDeferedError tcm -> do
diagsHie <- generateAndWriteHieFile hsc (tmrModule tcm)
diagsHie <- generateAndWriteHieFile hsc (tmrModule tcm) (fromMaybe "" source)
diagsHi <- writeHiFile hsc tcm
return (diags <> diagsHi <> diagsHie, Just tcm)
(diags, res) ->
Expand Down Expand Up @@ -801,9 +810,10 @@ regenerateHiFile sess f = do
case mb_pm of
Nothing -> return (diags, Nothing)
Just pm -> do
source <- getSourceFileSource f
-- Invoke typechecking directly to update it without incurring a dependency
-- on the parsed module and the typecheck rules
(diags', tmr) <- typeCheckRuleDefinition hsc pm DoGenerateInterfaceFiles
(diags', tmr) <- typeCheckRuleDefinition hsc pm DoGenerateInterfaceFiles (Just source)
-- Bang pattern is important to avoid leaking 'tmr'
let !res = extractHiFileResult tmr
return (diags <> diags', res)
Expand Down

0 comments on commit e2cb33d

Please sign in to comment.