@@ -437,8 +437,13 @@ getHieDbLoc dir = do
437
437
loadSession :: Recorder (WithPriority Log ) -> FilePath -> IO (Action IdeGhcSession )
438
438
loadSession recorder = loadSessionWithOptions recorder def
439
439
440
+ toAbsolute :: FilePath -> FilePath -> FilePath
441
+ toAbsolute dir file
442
+ | isAbsolute file = file
443
+ | otherwise = dir </> file
440
444
loadSessionWithOptions :: Recorder (WithPriority Log ) -> SessionLoadingOptions -> FilePath -> IO (Action IdeGhcSession )
441
445
loadSessionWithOptions recorder SessionLoadingOptions {.. } dir = do
446
+ let toAbsolutePath = toAbsolute dir
442
447
cradle_files <- newIORef []
443
448
-- Mapping from hie.yaml file to HscEnv, one per hie.yaml file
444
449
hscEnvs <- newVar Map. empty :: IO (Var HieMap )
@@ -459,7 +464,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
459
464
-- Sometimes we get C:, sometimes we get c:, and sometimes we get a relative path
460
465
-- try and normalise that
461
466
-- e.g. see https://github.com/haskell/ghcide/issues/126
462
- res' <- traverse makeAbsolute res
467
+ let res' = toAbsolutePath <$> res
463
468
return $ normalise <$> res'
464
469
465
470
dummyAs <- async $ return (error " Uninitialised" )
@@ -521,7 +526,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
521
526
packageSetup (hieYaml, cfp, opts, libDir) = do
522
527
-- Parse DynFlags for the newly discovered component
523
528
hscEnv <- emptyHscEnv ideNc libDir
524
- newTargetDfs <- evalGhcEnv hscEnv $ setOptions cfp opts (hsc_dflags hscEnv)
529
+ newTargetDfs <- evalGhcEnv hscEnv $ setOptions cfp opts (hsc_dflags hscEnv) dir
525
530
let deps = componentDependencies opts ++ maybeToList hieYaml
526
531
dep_info <- getDependencyInfo deps
527
532
-- Now lookup to see whether we are combining with an existing HscEnv
@@ -588,7 +593,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
588
593
-- HscEnv but set the active component accordingly
589
594
hscEnv <- emptyHscEnv ideNc _libDir
590
595
let new_cache = newComponentCache recorder optExtensions hieYaml _cfp hscEnv
591
- all_target_details <- new_cache old_deps new_deps
596
+ all_target_details <- new_cache old_deps new_deps dir
592
597
593
598
this_dep_info <- getDependencyInfo $ maybeToList hieYaml
594
599
let (all_targets, this_flags_map, this_options)
@@ -713,7 +718,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
713
718
modifyVar_ hscEnvs (const (return Map. empty))
714
719
715
720
v <- Map. findWithDefault HM. empty hieYaml <$> readVar fileToFlags
716
- cfp <- makeAbsolute file
721
+ let cfp = toAbsolutePath file
717
722
case HM. lookup (toNormalizedFilePath' cfp) v of
718
723
Just (opts, old_di) -> do
719
724
deps_ok <- checkDependencyInfo old_di
@@ -735,7 +740,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
735
740
-- before attempting to do so.
736
741
let getOptions :: FilePath -> IO (IdeResult HscEnvEq , [FilePath ])
737
742
getOptions file = do
738
- ncfp <- toNormalizedFilePath' <$> makeAbsolute file
743
+ let ncfp = toNormalizedFilePath' (toAbsolutePath file)
739
744
cachedHieYamlLocation <- HM. lookup ncfp <$> readVar filesMap
740
745
hieYaml <- cradleLoc file
741
746
sessionOpts (join cachedHieYamlLocation <|> hieYaml, file) `Safe.catch` \ e ->
@@ -747,7 +752,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
747
752
void $ wait as
748
753
asyncRes <- async $ getOptions file
749
754
return (asyncRes, wait asyncRes)
750
- pure opts
755
+ pure $ ( fmap . fmap ) toAbsolutePath opts
751
756
752
757
-- | Run the specific cradle on a specific FilePath via hie-bios.
753
758
-- This then builds dependencies or whatever based on the cradle, gets the
@@ -814,19 +819,20 @@ fromTargetId :: [FilePath] -- ^ import paths
814
819
-> TargetId
815
820
-> IdeResult HscEnvEq
816
821
-> DependencyInfo
822
+ -> FilePath
817
823
-> IO [TargetDetails ]
818
824
-- For a target module we consider all the import paths
819
- fromTargetId is exts (GHC. TargetModule modName) env dep = do
825
+ fromTargetId is exts (GHC. TargetModule modName) env dep dir = do
820
826
let fps = [i </> moduleNameSlashes modName -<.> ext <> boot
821
827
| ext <- exts
822
828
, i <- is
823
829
, boot <- [" " , " -boot" ]
824
830
]
825
- locs <- mapM ( fmap toNormalizedFilePath' . makeAbsolute ) fps
831
+ let locs = fmap ( toNormalizedFilePath' . toAbsolute dir ) fps
826
832
return [TargetDetails (TargetModule modName) env dep locs]
827
833
-- For a 'TargetFile' we consider all the possible module names
828
- fromTargetId _ _ (GHC. TargetFile f _) env deps = do
829
- nf <- toNormalizedFilePath' <$> makeAbsolute f
834
+ fromTargetId _ _ (GHC. TargetFile f _) env deps dir = do
835
+ let nf = toNormalizedFilePath' $ toAbsolute dir f
830
836
let other
831
837
| " -boot" `isSuffixOf` f = toNormalizedFilePath' (L. dropEnd 5 $ fromNormalizedFilePath nf)
832
838
| otherwise = toNormalizedFilePath' (fromNormalizedFilePath nf ++ " -boot" )
@@ -915,8 +921,9 @@ newComponentCache
915
921
-> HscEnv -- ^ An empty HscEnv
916
922
-> [ComponentInfo ] -- ^ New components to be loaded
917
923
-> [ComponentInfo ] -- ^ old, already existing components
924
+ -> FilePath -- ^ root dir
918
925
-> IO [ [TargetDetails ] ]
919
- newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
926
+ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis dir = do
920
927
let cis = Map. unionWith unionCIs (mkMap new_cis) (mkMap old_cis)
921
928
-- When we have multiple components with the same uid,
922
929
-- prefer the new one over the old.
@@ -961,7 +968,7 @@ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
961
968
962
969
forM (Map. elems cis) $ \ ci -> do
963
970
let df = componentDynFlags ci
964
- let createHscEnvEq = maybe newHscEnvEqPreserveImportPaths newHscEnvEq cradlePath
971
+ let createHscEnvEq = maybe newHscEnvEqPreserveImportPaths ( newHscEnvEq dir) cradlePath
965
972
thisEnv <- do
966
973
#if MIN_VERSION_ghc(9,3,0)
967
974
-- In GHC 9.4 we have multi component support, and we have initialised all the units
@@ -986,7 +993,7 @@ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
986
993
logWith recorder Debug $ LogNewComponentCache (targetEnv, targetDepends)
987
994
evaluate $ liftRnf rwhnf $ componentTargets ci
988
995
989
- let mk t = fromTargetId (importPaths df) exts (targetId t) targetEnv targetDepends
996
+ let mk t = fromTargetId (importPaths df) exts (targetId t) targetEnv targetDepends dir
990
997
ctargets <- concatMapM mk (componentTargets ci)
991
998
992
999
return (L. nubOrdOn targetTarget ctargets)
@@ -1171,8 +1178,8 @@ addUnit unit_str = liftEwM $ do
1171
1178
putCmdLineState (unit_str : units)
1172
1179
1173
1180
-- | Throws if package flags are unsatisfiable
1174
- setOptions :: GhcMonad m => NormalizedFilePath -> ComponentOptions -> DynFlags -> m (NonEmpty (DynFlags , [GHC. Target ]))
1175
- setOptions cfp (ComponentOptions theOpts compRoot _) dflags = do
1181
+ setOptions :: GhcMonad m => NormalizedFilePath -> ComponentOptions -> DynFlags -> FilePath -> m (NonEmpty (DynFlags , [GHC. Target ]))
1182
+ setOptions cfp (ComponentOptions theOpts compRoot _) dflags dir = do
1176
1183
((theOpts',_errs,_warns),units) <- processCmdLineP unit_flags [] (map noLoc theOpts)
1177
1184
case NE. nonEmpty units of
1178
1185
Just us -> initMulti us
@@ -1195,7 +1202,7 @@ setOptions cfp (ComponentOptions theOpts compRoot _) dflags = do
1195
1202
--
1196
1203
-- If we don't end up with a target for the current file in the end, then
1197
1204
-- we will report it as an error for that file
1198
- abs_fp <- liftIO $ makeAbsolute (fromNormalizedFilePath cfp)
1205
+ let abs_fp = toAbsolute dir (fromNormalizedFilePath cfp)
1199
1206
let special_target = Compat. mkSimpleTarget df abs_fp
1200
1207
pure $ (df, special_target : targets) :| []
1201
1208
where
0 commit comments