Skip to content

Commit 4177048

Browse files
committed
fixes
1 parent 59dead0 commit 4177048

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ import Development.IDE.GHC.Compat.CmdLine
116116
import GHC.Driver.Errors.Types
117117
import GHC.Driver.Env (hscSetActiveUnitId, hsc_all_home_unit_ids)
118118
import GHC.Driver.Make (checkHomeUnitsClosed)
119-
#endif
120119
import GHC.Unit.State
121-
import qualified Data.List.NonEmpty as NE
122-
import GHC.ResponseFile
123120
import GHC.Unit.Env
124121
import GHC.Types.Error (errMsgDiagnostic)
125122
import GHC.Data.Bag
123+
#endif
124+
import GHC.ResponseFile
125+
import qualified Data.List.NonEmpty as NE
126126

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

0 commit comments

Comments
 (0)