@@ -41,8 +41,8 @@ import Data.Hashable hiding (hash)
4141import qualified Data.HashMap.Strict as HM
4242import Data.IORef
4343import Data.List
44- import Data.List.NonEmpty (NonEmpty (.. ))
4544import Data.List.Extra as L
45+ import Data.List.NonEmpty (NonEmpty (.. ))
4646import qualified Data.List.NonEmpty as NE
4747import qualified Data.Map.Strict as Map
4848import Data.Maybe
@@ -113,22 +113,23 @@ import System.Random (RandomGen)
113113
114114import qualified Development.IDE.Session.Implicit as GhcIde
115115
116- import Development.IDE.GHC.Compat.CmdLine
116+ import Development.IDE.GHC.Compat.CmdLine
117117
118118
119119-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]
120120#if MIN_VERSION_ghc(9,3,0)
121121import qualified Data.Set as OS
122122
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
129130#endif
130131
131- import GHC.ResponseFile
132+ import GHC.ResponseFile
132133
133134data Log
134135 = LogSettingInitialDynFlags
@@ -479,12 +480,28 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
479480 -- files in the project so that `knownFiles` can learn about them and
480481 -- we can generate a complete module graph
481482 let extendKnownTargets newTargets = do
482- knownTargets <- forM newTargets $ \ TargetDetails {.. } ->
483+ knownTargets <- concatForM newTargets $ \ TargetDetails {.. } ->
483484 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))
485502 TargetModule _ -> do
486503 found <- filterM (IO. doesFileExist . fromNormalizedFilePath) targetLocations
487- return (targetTarget, found)
504+ return [ (targetTarget, found)]
488505 hasUpdate <- join $ atomically $ do
489506 known <- readTVar knownTargetsVar
490507 let known' = flip mapHashed known $ \ k ->
@@ -981,13 +998,13 @@ data ComponentInfo = ComponentInfo
981998 -- | Internal units, such as local libraries, that this component
982999 -- is loaded with. These have been extracted from the original
9831000 -- ComponentOptions.
984- , componentInternalUnits :: [UnitId ]
1001+ , componentInternalUnits :: [UnitId ]
9851002 -- | All targets of this components.
9861003 , componentTargets :: [GHC. Target ]
9871004 -- | Filepath which caused the creation of this component
9881005 , componentFP :: NormalizedFilePath
9891006 -- | Component Options used to load the component.
990- , componentCOptions :: ComponentOptions
1007+ , componentCOptions :: ComponentOptions
9911008 -- | Maps cradle dependencies, such as `stack.yaml`, or `.cabal` file
9921009 -- to last modification time. See Note [Multi Cradle Dependency Info]
9931010 , componentDependencyInfo :: DependencyInfo
@@ -1112,7 +1129,7 @@ setOptions cfp (ComponentOptions theOpts compRoot _) dflags = do
11121129
11131130 let targets = makeTargetsAbsolute root targets'
11141131 root = case workingDirectory dflags'' of
1115- Nothing -> compRoot
1132+ Nothing -> compRoot
11161133 Just wdir -> compRoot </> wdir
11171134 let dflags''' =
11181135 setWorkingDirectory root $
0 commit comments