Skip to content

Commit

Permalink
Use optExtensions in Session loader (haskell/ghcide#816)
Browse files Browse the repository at this point in the history
* Use optExtensions in Session loader

* Add boot suffix to target possible extensions
  • Loading branch information
pepeiborra committed Sep 17, 2020
1 parent c975590 commit 7e2a79b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ loadSession dir = do
IdeOptions{ optTesting = IdeTesting optTesting
, optCheckProject = CheckProject checkProject
, optCustomDynFlags
, optExtensions
} <- getIdeOptions

-- populate the knownTargetsVar with all the
Expand Down Expand Up @@ -227,7 +228,7 @@ loadSession dir = do

-- New HscEnv for the component in question, returns the new HscEnvEq and
-- a mapping from FilePath to the newly created HscEnvEq.
let new_cache = newComponentCache logger hieYaml hscEnv uids
let new_cache = newComponentCache logger optExtensions hieYaml hscEnv uids
(cs, res) <- new_cache new
-- Modified cache targets for everything else in the hie.yaml file
-- which now uses the same EPS and so on
Expand Down Expand Up @@ -380,18 +381,22 @@ data TargetDetails = TargetDetails
}

fromTargetId :: [FilePath] -- ^ import paths
-> [String] -- ^ extensions to consider
-> TargetId
-> IdeResult HscEnvEq
-> DependencyInfo
-> IO [TargetDetails]
-- For a target module we consider all the import paths
fromTargetId is (TargetModule mod) env dep = do
let fps = [i </> moduleNameSlashes mod -<.> ext | ext <- exts, i <- is ]
exts = ["hs", "hs-boot", "lhs"]
fromTargetId is exts (TargetModule mod) env dep = do
let fps = [i </> moduleNameSlashes mod -<.> ext <> boot
| ext <- exts
, i <- is
, boot <- ["", "-boot"]
]
locs <- mapM (fmap toNormalizedFilePath' . canonicalizePath) fps
return [TargetDetails mod env dep locs]
-- For a 'TargetFile' we consider all the possible module names
fromTargetId _ (TargetFile f _) env deps = do
fromTargetId _ _ (TargetFile f _) env deps = do
nf <- toNormalizedFilePath' <$> canonicalizePath f
return [TargetDetails m env deps [nf] | m <- moduleNames f]

Expand All @@ -417,12 +422,13 @@ setNameCache nc hsc = hsc { hsc_NC = nc }
-- | Create a mapping from FilePaths to HscEnvEqs
newComponentCache
:: Logger
-> [String] -- File extensions to consider
-> Maybe FilePath -- Path to cradle
-> HscEnv
-> [(InstalledUnitId, DynFlags)]
-> ComponentInfo
-> IO ( [TargetDetails], (IdeResult HscEnvEq, DependencyInfo))
newComponentCache logger cradlePath hsc_env uids ci = do
newComponentCache logger exts cradlePath hsc_env uids ci = do
let df = componentDynFlags ci
let hscEnv' = hsc_env { hsc_dflags = df
, hsc_IC = (hsc_IC hsc_env) { ic_dflags = df } }
Expand All @@ -434,7 +440,7 @@ newComponentCache logger cradlePath hsc_env uids ci = do
res = (targetEnv, targetDepends)
logDebug logger ("New Component Cache HscEnvEq: " <> T.pack (show res))

let mk t = fromTargetId (importPaths df) (targetId t) targetEnv targetDepends
let mk t = fromTargetId (importPaths df) exts (targetId t) targetEnv targetDepends
ctargets <- concatMapM mk (componentTargets ci)

-- A special target for the file which caused this wonderful
Expand Down

0 comments on commit 7e2a79b

Please sign in to comment.