Skip to content

Commit 4495464

Browse files
committed
Provide proper home unit id when using ghc 9.4
Also makes code compile (and still work) on ghc 9.2.
1 parent c48bdb9 commit 4495464

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,6 @@ runEvalCmd plId st EvalParams{..} =
245245

246246
now <- liftIO getCurrentTime
247247

248-
let modName = moduleName $ ms_mod ms
249-
thisModuleTarget =
250-
Target
251-
(TargetFile fp Nothing)
252-
False
253-
(stringToUnitId "blah-0.1.0.0-inplace")
254-
(Just (textToStringBuffer mdlText, now))
255248

256249
-- Setup environment for evaluation
257250
hscEnv' <- ExceptT $ fmap join $ liftIO . gStrictTry . evalGhcEnv session $ do
@@ -309,6 +302,15 @@ runEvalCmd plId st EvalParams{..} =
309302
-- BUG: this fails for files that requires preprocessors (e.g. CPP) for ghc < 8.8
310303
-- see https://gitlab.haskell.org/ghc/ghc/-/issues/17066
311304
-- and https://hackage.haskell.org/package/ghc-8.10.1/docs/GHC.html#v:TargetFile
305+
let modName = moduleName $ ms_mod ms
306+
thisModuleTarget =
307+
Target
308+
(TargetFile fp Nothing)
309+
False
310+
#if MIN_VERSION_ghc(9,3,0)
311+
(homeUnitId_ $ hsc_dflags session)
312+
#endif
313+
(Just (textToStringBuffer mdlText, now))
312314
eSetTarget <- gStrictTry $ setTargets [thisModuleTarget]
313315
dbg "setTarget" eSetTarget
314316

@@ -332,9 +334,12 @@ runEvalCmd plId st EvalParams{..} =
332334
lbs <- liftIO $ runAction "eval: GetLinkables" st $ do
333335
linkables_needed <- reachableModules <$> use_ GetDependencyInformation nfp
334336
uses_ GetLinkable (filter (/= nfp) linkables_needed) -- We don't need the linkable for the current module
335-
--let hscEnv'' = hscEnv' { hsc_HPT = addListToHpt (hsc_HPT hscEnv') [(moduleName $ mi_module $ hm_iface hm, hm) | lb <- lbs, let hm = linkableHomeMod lb] }
336-
let hscEnv'' =hscUpdateHPT (flip addListToHpt [(moduleName $ mi_module $ hm_iface hm, hm) | lb <- lbs, let hm = linkableHomeMod lb] ) hscEnv'
337337

338+
#if MIN_VERSION_ghc(9,3,0)
339+
let hscEnv'' = hscUpdateHPT (flip addListToHpt [(moduleName $ mi_module $ hm_iface hm, hm) | lb <- lbs, let hm = linkableHomeMod lb] ) hscEnv'
340+
#else
341+
let hscEnv'' = hscEnv' { hsc_HPT = addListToHpt (hsc_HPT hscEnv') [(moduleName $ mi_module $ hm_iface hm, hm) | lb <- lbs, let hm = linkableHomeMod lb] }
342+
#endif
338343
edits <-
339344
perf "edits" $
340345
liftIO $

0 commit comments

Comments
 (0)