@@ -41,8 +41,8 @@ import Data.Hashable hiding (hash)
41
41
import qualified Data.HashMap.Strict as HM
42
42
import Data.IORef
43
43
import Data.List
44
- import Data.List.NonEmpty (NonEmpty (.. ))
45
44
import Data.List.Extra as L
45
+ import Data.List.NonEmpty (NonEmpty (.. ))
46
46
import qualified Data.List.NonEmpty as NE
47
47
import qualified Data.Map.Strict as Map
48
48
import Data.Maybe
@@ -113,22 +113,23 @@ import System.Random (RandomGen)
113
113
114
114
import qualified Development.IDE.Session.Implicit as GhcIde
115
115
116
- import Development.IDE.GHC.Compat.CmdLine
116
+ import Development.IDE.GHC.Compat.CmdLine
117
117
118
118
119
119
-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]
120
120
#if MIN_VERSION_ghc(9,3,0)
121
121
import qualified Data.Set as OS
122
122
123
- import GHC.Driver.Errors.Types
124
- import GHC.Driver.Env (hscSetActiveUnitId , hsc_all_home_unit_ids )
125
- import GHC.Driver.Make (checkHomeUnitsClosed )
126
- import GHC.Unit.State
127
- import GHC.Types.Error (errMsgDiagnostic )
128
- import GHC.Data.Bag
123
+ import GHC.Data.Bag
124
+ import GHC.Driver.Env (hscSetActiveUnitId ,
125
+ hsc_all_home_unit_ids )
126
+ import GHC.Driver.Errors.Types
127
+ import GHC.Driver.Make (checkHomeUnitsClosed )
128
+ import GHC.Types.Error (errMsgDiagnostic )
129
+ import GHC.Unit.State
129
130
#endif
130
131
131
- import GHC.ResponseFile
132
+ import GHC.ResponseFile
132
133
133
134
data Log
134
135
= LogSettingInitialDynFlags
@@ -479,12 +480,28 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
479
480
-- files in the project so that `knownFiles` can learn about them and
480
481
-- we can generate a complete module graph
481
482
let extendKnownTargets newTargets = do
482
- knownTargets <- forM newTargets $ \ TargetDetails {.. } ->
483
+ knownTargets <- concatForM newTargets $ \ TargetDetails {.. } ->
483
484
case targetTarget of
484
- TargetFile f -> pure (targetTarget, [f])
485
+ TargetFile f -> do
486
+ -- If a target file has multiple possible locations, then we
487
+ -- assume they are all separate file targets.
488
+ -- This happens with '.hs-boot' files if they are in the root directory of the project.
489
+ -- GHC reports options such as '-i. A' as 'TargetFile A.hs' instead of 'TargetModule A'.
490
+ -- In 'fromTargetId', we dutifully look for '.hs-boot' files and add them to the
491
+ -- targetLocations of the TargetDetails. Then we add everything to the 'knownTargetsVar'.
492
+ -- However, when we look for a 'Foo.hs-boot' file in 'FindImports.hs', we look for either
493
+ --
494
+ -- * TargetFile Foo.hs-boot
495
+ -- * TargetModule Foo
496
+ --
497
+ -- If we don't generate a TargetFile for each potential location, we will only have
498
+ -- 'TargetFile Foo.hs' in the 'knownTargetsVar', thus not find 'TargetFile Foo.hs-boot'
499
+ -- and also not find 'TargetModule Foo'.
500
+ fs <- filterM (IO. doesFileExist . fromNormalizedFilePath) targetLocations
501
+ pure $ map (\ fp -> (TargetFile fp, [fp])) (nubOrd (f: fs))
485
502
TargetModule _ -> do
486
503
found <- filterM (IO. doesFileExist . fromNormalizedFilePath) targetLocations
487
- return (targetTarget, found)
504
+ return [ (targetTarget, found)]
488
505
hasUpdate <- join $ atomically $ do
489
506
known <- readTVar knownTargetsVar
490
507
let known' = flip mapHashed known $ \ k ->
@@ -975,13 +992,13 @@ data ComponentInfo = ComponentInfo
975
992
-- | Internal units, such as local libraries, that this component
976
993
-- is loaded with. These have been extracted from the original
977
994
-- ComponentOptions.
978
- , componentInternalUnits :: [UnitId ]
995
+ , componentInternalUnits :: [UnitId ]
979
996
-- | All targets of this components.
980
997
, componentTargets :: [GHC. Target ]
981
998
-- | Filepath which caused the creation of this component
982
999
, componentFP :: NormalizedFilePath
983
1000
-- | Component Options used to load the component.
984
- , componentCOptions :: ComponentOptions
1001
+ , componentCOptions :: ComponentOptions
985
1002
-- | Maps cradle dependencies, such as `stack.yaml`, or `.cabal` file
986
1003
-- to last modification time. See Note [Multi Cradle Dependency Info]
987
1004
, componentDependencyInfo :: DependencyInfo
@@ -1106,7 +1123,7 @@ setOptions cfp (ComponentOptions theOpts compRoot _) dflags = do
1106
1123
1107
1124
let targets = makeTargetsAbsolute root targets'
1108
1125
root = case workingDirectory dflags'' of
1109
- Nothing -> compRoot
1126
+ Nothing -> compRoot
1110
1127
Just wdir -> compRoot </> wdir
1111
1128
let dflags''' =
1112
1129
setWorkingDirectory root $
0 commit comments