Skip to content

Commit 856d961

Browse files
committed
fixes
1 parent a64996a commit 856d961

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

ghcide/session-loader/Development/IDE/Session.hs

+15-7
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ import Development.IDE.GHC.Compat.CmdLine
115115
import GHC.Driver.Errors.Types
116116
import GHC.Driver.Env (hscSetActiveUnitId, hsc_all_home_unit_ids)
117117
import GHC.Driver.Make (checkHomeUnitsClosed)
118-
#endif
119118
import GHC.Unit.State
120-
import qualified Data.List.NonEmpty as NE
121-
import GHC.ResponseFile
122119
import GHC.Unit.Env
123120
import GHC.Types.Error (errMsgDiagnostic)
124121
import GHC.Data.Bag
122+
#endif
123+
import GHC.ResponseFile
124+
import qualified Data.List.NonEmpty as NE
125125

126126
data Log
127127
= LogSettingInitialDynFlags
@@ -843,7 +843,7 @@ newComponentCache recorder exts cradlePath cfp hsc_env old_cis new_cis = do
843843
getSession
844844
#else
845845
-- getOptions is enough to initialize units on GHC <9.2
846-
pure $ hscSetFlags df hsc_env { hsc_IC = (hsc_IC hsc_env) { ic_dflags = init_df } }
846+
pure $ hscSetFlags df hsc_env { hsc_IC = (hsc_IC hsc_env) { ic_dflags = df } }
847847
#endif
848848
henv <- newFunc thisEnv uids
849849
let targetEnv = ([], Just henv)
@@ -866,9 +866,17 @@ newComponentCache recorder exts cradlePath cfp hsc_env old_cis new_cis = do
866866
| alreadyIncluded = xs
867867
| otherwise = let (as,bs) = break inIncludePath xs
868868
in case bs of
869-
[] -> as
869+
[] ->
870+
-- There is no appropriate target to add the file to, so pick one randomly
871+
case as of
872+
[] -> []
873+
((ctargets,res@(targetEnv, targetDepends)):xs) ->
874+
let x = (TargetDetails (TargetFile cfp) targetEnv targetDepends [cfp] : ctargets, res)
875+
in x:xs
876+
-- There is a component which could have this file in its include path
877+
-- pick one of these components
870878
((ctargets,res@(targetEnv, targetDepends)):bs) ->
871-
let b = (TargetDetails (TargetFile cfp) targetEnv targetDepends [cfp] : ctargets, res) -- todo what is componentFP used for
879+
let b = (TargetDetails (TargetFile cfp) targetEnv targetDepends [cfp] : ctargets, res)
872880
in as ++ (b:bs)
873881
where
874882
alreadyIncluded = any (any (cfp ==) . concatMap targetLocations . fst) xs
@@ -1066,7 +1074,7 @@ setOptions (ComponentOptions theOpts compRoot _) dflags = do
10661074
((theOpts',errs,warns),units) <- processCmdLineP unit_flags [] (map noLoc theOpts)
10671075
case NE.nonEmpty units of
10681076
Just us -> initMulti us
1069-
Nothing -> NE.singleton <$> initOne (map unLoc theOpts')
1077+
Nothing -> (NE.:| []) <$> initOne (map unLoc theOpts')
10701078
where
10711079
initMulti unitArgFiles =
10721080
forM unitArgFiles $ \f -> do

0 commit comments

Comments
 (0)