@@ -585,9 +585,21 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
585
585
let new_cache = newComponentCache recorder optExtensions hieYaml _cfp hscEnv
586
586
all_target_details <- new_cache old_deps new_deps
587
587
588
- let all_targets = concatMap fst all_target_details
589
-
590
- let this_flags_map = HM. fromList (concatMap toFlagsMap all_targets)
588
+ this_dep_info <- getDependencyInfo $ maybeToList hieYaml
589
+ let (all_targets, this_flags_map, this_options)
590
+ = case HM. lookup _cfp flags_map' of
591
+ Just this -> (all_targets', flags_map', this)
592
+ Nothing -> (this_target_details : all_targets', HM. insert _cfp this_flags flags_map', this_flags)
593
+ where all_targets' = concat all_target_details
594
+ flags_map' = HM. fromList (concatMap toFlagsMap all_targets')
595
+ this_target_details = TargetDetails (TargetFile _cfp) this_error_env this_dep_info [_cfp]
596
+ this_flags = (this_error_env, this_dep_info)
597
+ this_error_env = ([this_error], Nothing )
598
+ this_error = ideErrorWithSource (Just " cradle" ) (Just DiagnosticSeverity_Error ) _cfp
599
+ $ T. unlines
600
+ [ " No cradle target found. Is this file listed in the targets of your cradle?"
601
+ , " If you are using a .cabal file, please ensure that this module is listed in either the exposed-modules or other-modules section"
602
+ ]
591
603
592
604
void $ modifyVar' fileToFlags $
593
605
Map. insert hieYaml this_flags_map
@@ -615,7 +627,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
615
627
let ! exportsMap' = createExportsMap $ mapMaybe (fmap hirModIface) modIfaces
616
628
liftIO $ atomically $ modifyTVar' (exportsMap shakeExtras) (exportsMap' <> )
617
629
618
- return $ second Map. keys $ this_flags_map HM. ! _cfp
630
+ return $ second Map. keys this_options
619
631
620
632
let consultCradle :: Maybe FilePath -> FilePath -> IO (IdeResult HscEnvEq , [FilePath ])
621
633
consultCradle hieYaml cfp = do
@@ -810,7 +822,7 @@ newComponentCache
810
822
-> HscEnv -- ^ An empty HscEnv
811
823
-> [ComponentInfo ] -- ^ New components to be loaded
812
824
-> [ComponentInfo ] -- ^ old, already existing components
813
- -> IO [ ( [TargetDetails ], ( IdeResult HscEnvEq , DependencyInfo )) ]
825
+ -> IO [ [TargetDetails ] ]
814
826
newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
815
827
let cis = Map. unionWith unionCIs (mkMap new_cis) (mkMap old_cis)
816
828
-- When we have multiple components with the same uid,
@@ -882,14 +894,13 @@ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
882
894
henv <- createHscEnvEq thisEnv (zip uids dfs)
883
895
let targetEnv = (if isBad ci then multi_errs else [] , Just henv)
884
896
targetDepends = componentDependencyInfo ci
885
- res = ( targetEnv, targetDepends)
886
- logWith recorder Debug $ LogNewComponentCache res
897
+ logWith recorder Debug $ LogNewComponentCache (targetEnv, targetDepends)
887
898
evaluate $ liftRnf rwhnf $ componentTargets ci
888
899
889
900
let mk t = fromTargetId (importPaths df) exts (targetId t) targetEnv targetDepends
890
901
ctargets <- concatMapM mk (componentTargets ci)
891
902
892
- return (L. nubOrdOn targetTarget ctargets, res )
903
+ return (L. nubOrdOn targetTarget ctargets)
893
904
894
905
{- Note [Avoiding bad interface files]
895
906
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1081,15 +1092,20 @@ setOptions cfp (ComponentOptions theOpts compRoot _) dflags = do
1081
1092
-- A special target for the file which caused this wonderful
1082
1093
-- component to be created. In case the cradle doesn't list all the targets for
1083
1094
-- the component, in which case things will be horribly broken anyway.
1084
- -- Otherwise, we will immediately attempt to reload this module which
1085
- -- causes an infinite loop and high CPU usage.
1095
+ --
1096
+ -- When we have a single component that is caused to be loaded due to a
1097
+ -- file, we assume the file is part of that component. This is useful
1098
+ -- for bare GHC sessions, such as many of the ones used in the testsuite
1086
1099
--
1087
1100
-- We don't do this when we have multiple components, because each
1088
1101
-- component better list all targets or there will be anarchy.
1089
1102
-- It is difficult to know which component to add our file to in
1090
1103
-- that case.
1091
1104
-- Multi unit arguments are likely to come from cabal, which
1092
1105
-- does list all targets.
1106
+ --
1107
+ -- If we don't end up with a target for the current file in the end, then
1108
+ -- we will report it as an error for that file
1093
1109
abs_fp <- liftIO $ makeAbsolute (fromNormalizedFilePath cfp)
1094
1110
let special_target = Compat. mkSimpleTarget df abs_fp
1095
1111
pure $ (df, special_target : targets) :| []
0 commit comments