Skip to content

Commit e84ff76

Browse files
committed
Generate a FileTarget for each possible target location
If a target file has multiple possible locations, then we assume they are all separate file targets. This happens with '.hs-boot' files if they are in the root directory of the project. GHC reports options such as '-i. A' as 'TargetFile A.hs' instead of 'TargetModule A'. In 'fromTargetId', we dutifully look for '.hs-boot' files and add them to the targetLocations of the TargetDetails. Then we add everything to the 'knownTargetsVar'. However, when we look for a 'Foo.hs-boot' file in 'FindImports.hs', we look for either * TargetFile Foo.hs-boot * TargetModule Foo If we don't generate a TargetFile for each potential location, we will only have 'TargetFile Foo.hs' in the 'knownTargetsVar', thus not find 'TargetFile Foo.hs-boot' and also not find 'TargetModule Foo'.
1 parent e4a3e44 commit e84ff76

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

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

+19-3
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,28 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
479479
-- files in the project so that `knownFiles` can learn about them and
480480
-- we can generate a complete module graph
481481
let extendKnownTargets newTargets = do
482-
knownTargets <- forM newTargets $ \TargetDetails{..} ->
482+
knownTargets <- concatForM newTargets $ \TargetDetails{..} ->
483483
case targetTarget of
484-
TargetFile f -> pure (targetTarget, [f])
484+
TargetFile _ -> do
485+
-- If a target file has multiple possible locations, then we
486+
-- assume they are all separate file targets.
487+
-- This happens with '.hs-boot' files if they are in the root directory of the project.
488+
-- GHC reports options such as '-i. A' as 'TargetFile A.hs' instead of 'TargetModule A'.
489+
-- In 'fromTargetId', we dutifully look for '.hs-boot' files and add them to the
490+
-- targetLocations of the TargetDetails. Then we add everything to the 'knownTargetsVar'.
491+
-- However, when we look for a 'Foo.hs-boot' file in 'FindImports.hs', we look for either
492+
--
493+
-- * TargetFile Foo.hs-boot
494+
-- * TargetModule Foo
495+
--
496+
-- If we don't generate a TargetFile for each potential location, we will only have
497+
-- 'TargetFile Foo.hs' in the 'knownTargetsVar', thus not find 'TargetFile Foo.hs-boot'
498+
-- and also not find 'TargetModule Foo'.
499+
found <- filterM (IO.doesFileExist . fromNormalizedFilePath) targetLocations
500+
pure $ map (\f -> (TargetFile f, [f])) found
485501
TargetModule _ -> do
486502
found <- filterM (IO.doesFileExist . fromNormalizedFilePath) targetLocations
487-
return (targetTarget, found)
503+
return [(targetTarget, found)]
488504
hasUpdate <- join $ atomically $ do
489505
known <- readTVar knownTargetsVar
490506
let known' = flip mapHashed known $ \k ->

0 commit comments

Comments
 (0)