Skip to content

Commit

Permalink
Generate a FileTarget for each possible target location
Browse files Browse the repository at this point in the history
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'.
  • Loading branch information
fendor committed Dec 13, 2023
1 parent e4a3e44 commit 553e516
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,27 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
-- files in the project so that `knownFiles` can learn about them and
-- we can generate a complete module graph
let extendKnownTargets newTargets = do
knownTargets <- forM newTargets $ \TargetDetails{..} ->
knownTargets <- concatForM newTargets $ \TargetDetails{..} ->
case targetTarget of
TargetFile f -> pure (targetTarget, [f])
TargetFile _ -> do
-- 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'.
pure $ map (\f -> (TargetFile f, [f])) (nubOrd targetLocations)
TargetModule _ -> do
found <- filterM (IO.doesFileExist . fromNormalizedFilePath) targetLocations
return (targetTarget, found)
return [(targetTarget, found)]
hasUpdate <- join $ atomically $ do
known <- readTVar knownTargetsVar
let known' = flip mapHashed known $ \k ->
Expand Down

0 comments on commit 553e516

Please sign in to comment.