@@ -134,9 +134,12 @@ import GHC.Unit.State
134
134
import Language.LSP.Protocol.Types (NormalizedUri (NormalizedUri ),
135
135
toNormalizedFilePath )
136
136
#endif
137
+ import qualified Development.IDE.Core.Shake as SHake
137
138
138
139
data Log
140
+
139
141
= LogSettingInitialDynFlags
142
+ | LogShake SHake. Log
140
143
| LogGetInitialGhcLibDirDefaultCradleFail ! CradleError ! FilePath ! (Maybe FilePath ) ! (Cradle Void )
141
144
| LogGetInitialGhcLibDirDefaultCradleNone
142
145
| LogHieDbRetry ! Int ! Int ! Int ! SomeException
@@ -157,6 +160,7 @@ data Log
157
160
| LogSessionLoadingChanged
158
161
deriving instance Show Log
159
162
163
+
160
164
instance Pretty Log where
161
165
pretty = \ case
162
166
LogNoneCradleFound path ->
@@ -227,6 +231,7 @@ instance Pretty Log where
227
231
LogHieBios msg -> pretty msg
228
232
LogSessionLoadingChanged ->
229
233
" Session Loading config changed, reloading the full session."
234
+ LogShake msg -> pretty msg
230
235
231
236
-- | Bump this version number when making changes to the format of the data stored in hiedb
232
237
hiedbDataVersion :: String
@@ -440,10 +445,10 @@ getHieDbLoc dir = do
440
445
-- This is the key function which implements multi-component support. All
441
446
-- components mapping to the same hie.yaml file are mapped to the same
442
447
-- HscEnv which is updated as new components are discovered.
443
- loadSession :: Recorder (WithPriority Log ) -> FilePath -> IO (Action IdeGhcSession )
448
+ loadSession :: Recorder (WithPriority Log ) -> FilePath -> IO (Rules () , Action IdeGhcSession )
444
449
loadSession recorder = loadSessionWithOptions recorder def
445
450
446
- loadSessionWithOptions :: Recorder (WithPriority Log ) -> SessionLoadingOptions -> FilePath -> IO (Action IdeGhcSession )
451
+ loadSessionWithOptions :: Recorder (WithPriority Log ) -> SessionLoadingOptions -> FilePath -> IO (Rules () , Action IdeGhcSession )
447
452
loadSessionWithOptions recorder SessionLoadingOptions {.. } rootDir = do
448
453
let toAbsolutePath = toAbsolute rootDir
449
454
cradle_files <- newIORef []
@@ -463,7 +468,16 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir = do
463
468
biosSessionLoadingVar <- newVar Nothing :: IO (Var (Maybe SessionLoadingPreferenceConfig ))
464
469
let returnWithVersion fun = IdeGhcSession fun <$> liftIO (readVar version)
465
470
466
- return $ do
471
+ let cradleLocRule :: Rules ()
472
+ cradleLocRule = defineNoDiagnostics (cmapWithPrio LogShake recorder) $ \ CradleLoc file -> do
473
+ res <- liftIO $ HieBios. findCradle $ fromNormalizedFilePath file
474
+ -- Sometimes we get C:, sometimes we get c:, and sometimes we get a relative path
475
+ -- try and normalise that
476
+ -- e.g. see https://github.com/haskell/ghcide/issues/126
477
+ -- todo make it absolute
478
+ return $ Just (normalise . toAbsolutePath <$> res)
479
+
480
+ return $ (cradleLocRule, do
467
481
clientConfig <- getClientConfigAction
468
482
extras@ ShakeExtras {restartShakeSession, ideNc, knownTargetsVar, lspEnv
469
483
} <- getShakeExtras
@@ -612,30 +626,30 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir = do
612
626
keys2 <- liftIO $ invalidateShakeCache
613
627
614
628
-- todo this should be moving out of the session function
615
- restart <- liftIO $ async $ restartShakeSession VFSUnmodified " new component" [] $ do
616
- keys1 <- extendKnownTargets all_targets
617
- return [keys1, keys2]
629
+ restart <- liftIO $ async $ do
630
+ restartShakeSession VFSUnmodified " new component" [] $ do
631
+ keys1 <- extendKnownTargets all_targets
632
+ return [keys1, keys2]
633
+ -- Typecheck all files in the project on startup
634
+ checkProject <- liftIO $ getCheckProject
635
+ liftIO $ unless (null new_deps || not checkProject) $ do
636
+ cfps' <- liftIO $ filterM (IO. doesFileExist . fromNormalizedFilePath) (concatMap targetLocations all_targets)
637
+ void $ shakeEnqueue extras $ mkDelayedAction " InitialLoad" Debug $ void $ do
638
+ mmt <- uses GetModificationTime cfps'
639
+ let cs_exist = catMaybes (zipWith (<$) cfps' mmt)
640
+ modIfaces <- uses GetModIface cs_exist
641
+ -- update exports map
642
+ shakeExtras <- getShakeExtras
643
+ let ! exportsMap' = createExportsMap $ mapMaybe (fmap hirModIface) modIfaces
644
+ liftIO $ atomically $ modifyTVar' (exportsMap shakeExtras) (exportsMap' <> )
618
645
UnliftIO. wait restart
619
-
620
-
621
- -- Typecheck all files in the project on startup
622
- checkProject <- liftIO $ getCheckProject
623
- liftIO $ unless (null new_deps || not checkProject) $ do
624
- cfps' <- liftIO $ filterM (IO. doesFileExist . fromNormalizedFilePath) (concatMap targetLocations all_targets)
625
- void $ shakeEnqueue extras $ mkDelayedAction " InitialLoad" Debug $ void $ do
626
- mmt <- uses GetModificationTime cfps'
627
- let cs_exist = catMaybes (zipWith (<$) cfps' mmt)
628
- modIfaces <- uses GetModIface cs_exist
629
- -- update exports map
630
- shakeExtras <- getShakeExtras
631
- let ! exportsMap' = createExportsMap $ mapMaybe (fmap hirModIface) modIfaces
632
- liftIO $ atomically $ modifyTVar' (exportsMap shakeExtras) (exportsMap' <> )
633
-
634
646
return $ second Map. keys this_options
635
647
636
648
let consultCradle :: NormalizedFilePath -> Action (IdeResult HscEnvEq , [FilePath ])
637
649
consultCradle cfp = do
638
- hieYaml <- use_ CradleLoc cfp
650
+ hieYamlOld <- use_ CradleLoc cfp
651
+ cachedHieYamlLocation <- join <$> liftIO (HM. lookup cfp <$> readVar filesMap)
652
+ let hieYaml = fromMaybe cachedHieYamlLocation (Just hieYamlOld)
639
653
let lfpLog = makeRelative rootDir (fromNormalizedFilePath cfp)
640
654
logWith recorder Info $ LogCradlePath lfpLog
641
655
when (isNothing hieYaml) $
@@ -701,7 +715,9 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir = do
701
715
let sessionOpts :: NormalizedFilePath
702
716
-> Action (IdeResult HscEnvEq , [FilePath ])
703
717
sessionOpts file = do
704
- hieYaml <- use_ CradleLoc file
718
+ hieYamlOld <- use_ CradleLoc file
719
+ cachedHieYamlLocation <- join <$> liftIO (HM. lookup file <$> readVar filesMap)
720
+ let hieYaml = fromMaybe cachedHieYamlLocation (Just hieYamlOld)
705
721
-- this cased a recompilation of the whole project
706
722
-- this can be turned in to shake
707
723
liftIO$ Extra. whenM didSessionLoadingPreferenceConfigChange $ do
@@ -737,15 +753,15 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir = do
737
753
738
754
let getOptions :: NormalizedFilePath -> Action (IdeResult HscEnvEq , [FilePath ])
739
755
getOptions file = do
740
- -- cachedHieYamlLocation <- liftIO $ HM.lookup file <$> readVar filesMap
741
756
-- CradleLoc already cached
742
757
hieYaml <- use_ CradleLoc file
743
758
sessionOpts file `Safe.catch` \ e ->
744
759
return (([renderPackageSetupException file e], Nothing ), maybe [] pure hieYaml)
745
760
761
+
746
762
returnWithVersion $ \ file -> do
747
763
opts <- UnliftIO. withMVar cradleLock $ const $ getOptions file
748
- pure $ (fmap . fmap ) toAbsolutePath opts
764
+ pure $ (fmap . fmap ) toAbsolutePath opts)
749
765
750
766
751
767
-- | Run the specific cradle on a specific FilePath via hie-bios.
@@ -1074,6 +1090,9 @@ type FilesMap = HM.HashMap NormalizedFilePath (Maybe FilePath)
1074
1090
-- if some new file4 should be in hie1.yaml,
1075
1091
-- we need to recompute the hie1.yaml
1076
1092
1093
+ -- hieRule file
1094
+ -- get corresponding hie.yaml
1095
+
1077
1096
1078
1097
1079
1098
-- This is pristine information about a component
0 commit comments