diff --git a/ghcide/session-loader/Development/IDE/Session.hs b/ghcide/session-loader/Development/IDE/Session.hs index 286eec87ee..e725c6acc4 100644 --- a/ghcide/session-loader/Development/IDE/Session.hs +++ b/ghcide/session-loader/Development/IDE/Session.hs @@ -90,6 +90,9 @@ import HieDb.Types import HieDb.Utils import Maybes (MaybeT (runMaybeT)) +-- | Bump this version number when making changes to the format of the data stored in hiedb +hiedbDataVersion :: String +hiedbDataVersion = "1" data CacheDirs = CacheDirs { hiCacheDir, hieCacheDir, oCacheDir :: Maybe FilePath} @@ -103,6 +106,11 @@ data SessionLoadingOptions = SessionLoadingOptions , getCacheDirs :: String -> [String] -> IO CacheDirs -- | Return the GHC lib dir to use for the 'unsafeGlobalDynFlags' , getInitialGhcLibDir :: IO (Maybe LibDir) + , fakeUid :: InstalledUnitId + -- ^ unit id used to tag the internal component built by ghcide + -- To reuse external interface files the unit ids must match, + -- thus make sure to build them with `--this-unit-id` set to the + -- same value as the ghcide fake uid } instance Default SessionLoadingOptions where @@ -111,6 +119,7 @@ instance Default SessionLoadingOptions where ,loadCradle = HieBios.loadCradle ,getCacheDirs = getCacheDirsDefault ,getInitialGhcLibDir = getInitialGhcLibDirDefault + ,fakeUid = toInstalledUnitId (stringToUnitId "main") } getInitialGhcLibDirDefault :: IO (Maybe LibDir) @@ -167,7 +176,7 @@ runWithDb fp k = do getHieDbLoc :: FilePath -> IO FilePath getHieDbLoc dir = do - let db = dirHash++"-"++takeBaseName dir++"-"++VERSION_ghc <.> "hiedb" + let db = intercalate "-" [dirHash, takeBaseName dir, VERSION_ghc, hiedbDataVersion] <.> "hiedb" dirHash = B.unpack $ B16.encode $ H.hash $ B.pack dir cDir <- IO.getXdgDirectory IO.XdgCache cacheDir createDirectoryIfMissing True cDir @@ -277,7 +286,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do new_deps' <- forM new_deps $ \RawComponentInfo{..} -> do -- Remove all inplace dependencies from package flags for -- components in this HscEnv - let (df2, uids) = removeInplacePackages inplace rawComponentDynFlags + let (df2, uids) = removeInplacePackages fakeUid inplace rawComponentDynFlags let prefix = show rawComponentUnitId -- See Note [Avoiding bad interface files] let hscComponents = sort $ map show uids @@ -716,12 +725,15 @@ getDependencyInfo fs = Map.fromList <$> mapM do_one fs -- There are several places in GHC (for example the call to hptInstances in -- tcRnImports) which assume that all modules in the HPT have the same unit -- ID. Therefore we create a fake one and give them all the same unit id. -removeInplacePackages :: [InstalledUnitId] -> DynFlags -> (DynFlags, [InstalledUnitId]) -removeInplacePackages us df = (df { packageFlags = ps +removeInplacePackages + :: InstalledUnitId -- ^ fake uid to use for our internal component + -> [InstalledUnitId] + -> DynFlags + -> (DynFlags, [InstalledUnitId]) +removeInplacePackages fake_uid us df = (df { packageFlags = ps , thisInstalledUnitId = fake_uid }, uids) where (uids, ps) = partitionEithers (map go (packageFlags df)) - fake_uid = toInstalledUnitId (stringToUnitId "fake_uid") go p@(ExposePackage _ (UnitIdArg u) _) = if toInstalledUnitId u `elem` us then Left (toInstalledUnitId u) else Right p diff --git a/ghcide/src/Development/IDE/Core/Compile.hs b/ghcide/src/Development/IDE/Core/Compile.hs index 1e007b6ccc..f8fdcd36c4 100644 --- a/ghcide/src/Development/IDE/Core/Compile.hs +++ b/ghcide/src/Development/IDE/Core/Compile.hs @@ -571,7 +571,7 @@ indexHieFile se mod_summary srcPath hash hf = atomically $ do LSP.sendNotification LSP.SProgress $ LSP.ProgressParams tok $ LSP.Report $ LSP.WorkDoneProgressReportParams { _cancellable = Nothing - , _message = Just $ T.pack (show srcPath) <> progress + , _message = Just $ T.pack (fromNormalizedFilePath srcPath) <> progress , _percentage = Nothing } diff --git a/ghcide/src/Development/IDE/Core/Rules.hs b/ghcide/src/Development/IDE/Core/Rules.hs index 0846593bdc..c307a9c1b0 100644 --- a/ghcide/src/Development/IDE/Core/Rules.hs +++ b/ghcide/src/Development/IDE/Core/Rules.hs @@ -842,7 +842,7 @@ getModIfaceFromDiskAndIndexRule = defineEarlyCutoff $ \GetModIfaceFromDiskAndInd Left err -> fail $ "failed to read .hie file " ++ show hie_loc ++ ": " ++ displayException err -- can just re-index the file we read from disk Right hf -> liftIO $ do - L.logDebug (logger se) $ "Re-indexing hie file for" <> T.pack (show f) + L.logDebug (logger se) $ "Re-indexing hie file for" <> T.pack (fromNormalizedFilePath f) indexHieFile se ms f hash hf let fp = hiFileFingerPrint x