Skip to content

Commit 67bd247

Browse files
authored
Merge branch 'master' into eval-ghc901
2 parents 2cddd76 + 4ae0fea commit 67bd247

File tree

5 files changed

+46
-20
lines changed

5 files changed

+46
-20
lines changed

ghcide/src/Development/IDE/Core/Actions.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ import Development.IDE.GHC.Compat hiding (TargetFile,
3030
writeHieFile)
3131
import Development.IDE.Graph
3232
import qualified Development.IDE.Spans.AtPoint as AtPoint
33+
import Development.IDE.Types.HscEnvEq (hscEnv)
3334
import Development.IDE.Types.Location
3435
import qualified HieDb
36+
import HscTypes (hsc_dflags)
3537
import Language.LSP.Types (DocumentHighlight (..),
3638
SymbolInformation (..))
3739

@@ -62,10 +64,11 @@ getAtPoint file pos = runMaybeT $ do
6264
opts <- liftIO $ getIdeOptionsIO ide
6365

6466
(hf, mapping) <- useE GetHieAst file
65-
dkMap <- lift $ maybe (DKMap mempty mempty) fst <$> (runMaybeT $ useE GetDocMap file)
67+
df <- hsc_dflags . hscEnv . fst <$> useE GhcSession file
68+
dkMap <- lift $ maybe (DKMap mempty mempty) fst <$> runMaybeT (useE GetDocMap file)
6669

6770
!pos' <- MaybeT (return $ fromCurrentPosition mapping pos)
68-
MaybeT $ pure $ fmap (first (toCurrentRange mapping =<<)) $ AtPoint.atPoint opts hf dkMap pos'
71+
MaybeT $ pure $ first (toCurrentRange mapping =<<) <$> AtPoint.atPoint opts hf dkMap df pos'
6972

7073
toCurrentLocations :: PositionMapping -> [Location] -> [Location]
7174
toCurrentLocations mapping = mapMaybe go

ghcide/src/Development/IDE/Core/Rules.hs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ import Ide.Plugin.Properties (HasProperty,
151151
import Ide.PluginUtils (configForPlugin)
152152
import Ide.Types (DynFlagsModifications (dynFlagsModifyGlobal, dynFlagsModifyParser),
153153
PluginId)
154+
import qualified Data.HashSet as HS
154155

155156
-- | This is useful for rules to convert rules that can only produce errors or
156157
-- a result into the more general IdeResult type that supports producing
@@ -311,6 +312,7 @@ getLocatedImportsRule =
311312
define $ \GetLocatedImports file -> do
312313
ModSummaryResult{msrModSummary = ms} <- use_ GetModSummaryWithoutTimestamps file
313314
targets <- useNoFile_ GetKnownTargets
315+
let targetsMap = HM.mapWithKey const targets
314316
let imports = [(False, imp) | imp <- ms_textual_imps ms] ++ [(True, imp) | imp <- ms_srcimps ms]
315317
env_eq <- use_ GhcSession file
316318
let env = hscEnvWithImportPaths env_eq
@@ -321,14 +323,24 @@ getLocatedImportsRule =
321323
then addRelativeImport file (moduleName $ ms_mod ms) dflags
322324
else dflags
323325
opt <- getIdeOptions
324-
let getTargetExists modName nfp
325-
| isImplicitCradle = getFileExists nfp
326-
| HM.member (TargetModule modName) targets
327-
|| HM.member (TargetFile nfp) targets
328-
= getFileExists nfp
329-
| otherwise = return False
326+
let getTargetFor modName nfp
327+
| isImplicitCradle = do
328+
itExists <- getFileExists nfp
329+
return $ if itExists then Just nfp else Nothing
330+
| Just (TargetFile nfp') <- HM.lookup (TargetFile nfp) targetsMap = do
331+
-- reuse the existing NormalizedFilePath in order to maximize sharing
332+
itExists <- getFileExists nfp'
333+
return $ if itExists then Just nfp' else Nothing
334+
| Just tt <- HM.lookup (TargetModule modName) targets = do
335+
-- reuse the existing NormalizedFilePath in order to maximize sharing
336+
let ttmap = HM.mapWithKey const (HS.toMap tt)
337+
nfp' = HM.lookupDefault nfp nfp ttmap
338+
itExists <- getFileExists nfp'
339+
return $ if itExists then Just nfp' else Nothing
340+
| otherwise
341+
= return Nothing
330342
(diags, imports') <- fmap unzip $ forM imports $ \(isSource, (mbPkgName, modName)) -> do
331-
diagOrImp <- locateModule dflags import_dirs (optExtensions opt) getTargetExists modName mbPkgName isSource
343+
diagOrImp <- locateModule dflags import_dirs (optExtensions opt) getTargetFor modName mbPkgName isSource
332344
case diagOrImp of
333345
Left diags -> pure (diags, Just (modName, Nothing))
334346
Right (FileImport path) -> pure ([], Just (modName, Just path))

ghcide/src/Development/IDE/Import/FindImports.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ modSummaryToArtifactsLocation nfp ms = ArtifactsLocation nfp (ms_location <$> ms
6969
locateModuleFile :: MonadIO m
7070
=> [[FilePath]]
7171
-> [String]
72-
-> (ModuleName -> NormalizedFilePath -> m Bool)
72+
-> (ModuleName -> NormalizedFilePath -> m (Maybe NormalizedFilePath))
7373
-> Bool
7474
-> ModuleName
7575
-> m (Maybe NormalizedFilePath)
76-
locateModuleFile import_dirss exts doesExist isSource modName = do
76+
locateModuleFile import_dirss exts targetFor isSource modName = do
7777
let candidates import_dirs =
7878
[ toNormalizedFilePath' (prefix </> M.moduleNameSlashes modName <.> maybeBoot ext)
7979
| prefix <- import_dirs , ext <- exts]
80-
findM (doesExist modName) (concatMap candidates import_dirss)
80+
firstJustM (targetFor modName) (concatMap candidates import_dirss)
8181
where
8282
maybeBoot ext
8383
| isSource = ext ++ "-boot"
@@ -97,12 +97,12 @@ locateModule
9797
=> DynFlags
9898
-> [(Compat.InstalledUnitId, DynFlags)] -- ^ Import directories
9999
-> [String] -- ^ File extensions
100-
-> (ModuleName -> NormalizedFilePath -> m Bool) -- ^ does file exist predicate
100+
-> (ModuleName -> NormalizedFilePath -> m (Maybe NormalizedFilePath)) -- ^ does file exist predicate
101101
-> Located ModuleName -- ^ Module name
102102
-> Maybe FastString -- ^ Package name
103103
-> Bool -- ^ Is boot module
104104
-> m (Either [FileDiagnostic] Import)
105-
locateModule dflags comp_info exts doesExist modName mbPkgName isSource = do
105+
locateModule dflags comp_info exts targetFor modName mbPkgName isSource = do
106106
case mbPkgName of
107107
-- "this" means that we should only look in the current package
108108
Just "this" -> do
@@ -118,7 +118,7 @@ locateModule dflags comp_info exts doesExist modName mbPkgName isSource = do
118118
-- Here the importPaths for the current modules are added to the front of the import paths from the other components.
119119
-- This is particularly important for Paths_* modules which get generated for every component but unless you use it in
120120
-- each component will end up being found in the wrong place and cause a multi-cradle match failure.
121-
mbFile <- locateModuleFile (importPaths dflags : map snd import_paths) exts doesExist isSource $ unLoc modName
121+
mbFile <- locateModuleFile (importPaths dflags : map snd import_paths) exts targetFor isSource $ unLoc modName
122122
case mbFile of
123123
Nothing -> lookupInPackageDB dflags
124124
Just file -> toModLocation file
@@ -129,7 +129,7 @@ locateModule dflags comp_info exts doesExist modName mbPkgName isSource = do
129129
return $ Right $ FileImport $ ArtifactsLocation file (Just loc) (not isSource)
130130

131131
lookupLocal dirs = do
132-
mbFile <- locateModuleFile dirs exts doesExist isSource $ unLoc modName
132+
mbFile <- locateModuleFile dirs exts targetFor isSource $ unLoc modName
133133
case mbFile of
134134
Nothing -> return $ Left $ notFoundErr dflags modName $ LookupNotFound []
135135
Just file -> toModLocation file

ghcide/src/Development/IDE/Spans/AtPoint.hs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import Data.Either
5656
import Data.List (isSuffixOf)
5757
import Data.List.Extra (dropEnd1, nubOrd)
5858

59+
import Data.Version (showVersion)
5960
import HieDb hiding (pointCommand)
6061
import System.Directory (doesFileExist)
6162

@@ -196,9 +197,10 @@ atPoint
196197
:: IdeOptions
197198
-> HieAstResult
198199
-> DocAndKindMap
200+
-> DynFlags
199201
-> Position
200202
-> Maybe (Maybe Range, [T.Text])
201-
atPoint IdeOptions{} (HAR _ hf _ _ kind) (DKMap dm km) pos = listToMaybe $ pointCommand hf pos hoverInfo
203+
atPoint IdeOptions{} (HAR _ hf _ _ kind) (DKMap dm km) df pos = listToMaybe $ pointCommand hf pos hoverInfo
202204
where
203205
-- Hover info for values/data
204206
hoverInfo ast = (Just range, prettyNames ++ pTypes)
@@ -219,11 +221,20 @@ atPoint IdeOptions{} (HAR _ hf _ _ kind) (DKMap dm km) pos = listToMaybe $ point
219221
prettyName (Right n, dets) = T.unlines $
220222
wrapHaskell (showNameWithoutUniques n <> maybe "" (" :: " <>) ((prettyType <$> identType dets) <|> maybeKind))
221223
: definedAt n
224+
++ maybeToList (prettyPackageName n)
222225
++ catMaybes [ T.unlines . spanDocToMarkdown <$> lookupNameEnv dm n
223226
]
224227
where maybeKind = fmap showGhc $ safeTyThingType =<< lookupNameEnv km n
225228
prettyName (Left m,_) = showGhc m
226229

230+
prettyPackageName n = do
231+
m <- nameModule_maybe n
232+
let pid = moduleUnitId m
233+
conf <- lookupPackage df pid
234+
let pkgName = T.pack $ packageNameString conf
235+
version = T.pack $ showVersion (packageVersion conf)
236+
pure $ " *(" <> pkgName <> "-" <> version <> ")*"
237+
227238
prettyTypes = map (("_ :: "<>) . prettyType) types
228239
prettyType t = case kind of
229240
HieFresh -> showGhc t

ghcide/test/exe/Main.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3591,17 +3591,17 @@ findDefinitionAndHoverTests = let
35913591
aaaL14 = Position 18 20 ; aaa = [mkR 11 0 11 3]
35923592
dcL7 = Position 11 11 ; tcDC = [mkR 7 23 9 16]
35933593
dcL12 = Position 16 11 ;
3594-
xtcL5 = Position 9 11 ; xtc = [ExpectExternFail, ExpectHoverText ["Int", "Defined in ", "GHC.Types"]]
3594+
xtcL5 = Position 9 11 ; xtc = [ExpectExternFail, ExpectHoverText ["Int", "Defined in ", "GHC.Types", "ghc-prim"]]
35953595
tcL6 = Position 10 11 ; tcData = [mkR 7 0 9 16, ExpectHoverText ["TypeConstructor", "GotoHover.hs:8:1"]]
35963596
vvL16 = Position 20 12 ; vv = [mkR 20 4 20 6]
35973597
opL16 = Position 20 15 ; op = [mkR 21 2 21 4]
35983598
opL18 = Position 22 22 ; opp = [mkR 22 13 22 17]
35993599
aL18 = Position 22 20 ; apmp = [mkR 22 10 22 11]
36003600
b'L19 = Position 23 13 ; bp = [mkR 23 6 23 7]
3601-
xvL20 = Position 24 8 ; xvMsg = [ExpectExternFail, ExpectHoverText ["pack", ":: String -> Text", "Data.Text"]]
3601+
xvL20 = Position 24 8 ; xvMsg = [ExpectExternFail, ExpectHoverText ["pack", ":: String -> Text", "Data.Text", "text"]]
36023602
clL23 = Position 27 11 ; cls = [mkR 25 0 26 20, ExpectHoverText ["MyClass", "GotoHover.hs:26:1"]]
36033603
clL25 = Position 29 9
3604-
eclL15 = Position 19 8 ; ecls = [ExpectExternFail, ExpectHoverText ["Num", "Defined in ", "GHC.Num"]]
3604+
eclL15 = Position 19 8 ; ecls = [ExpectExternFail, ExpectHoverText ["Num", "Defined in ", "GHC.Num", "base"]]
36053605
dnbL29 = Position 33 18 ; dnb = [ExpectHoverText [":: ()"], mkR 33 12 33 21]
36063606
dnbL30 = Position 34 23
36073607
lcbL33 = Position 37 26 ; lcb = [ExpectHoverText [":: Char"], mkR 37 26 37 27]

0 commit comments

Comments
 (0)