@@ -35,7 +35,8 @@ import Development.IDE.Core.PositionMapping
35
35
import Development.IDE.Core.RuleTypes
36
36
import Development.IDE.GHC.Compat
37
37
import qualified Development.IDE.GHC.Compat.Util as Util
38
- import Development.IDE.GHC.Util (printOutputable )
38
+ import Development.IDE.GHC.Util (evalGhcEnv ,
39
+ printOutputable )
39
40
import Development.IDE.Spans.Common
40
41
import Development.IDE.Types.Options
41
42
@@ -57,6 +58,7 @@ import Data.List.Extra (dropEnd1, nubOrd)
57
58
58
59
import Data.Version (showVersion )
59
60
import Development.IDE.Types.Shake (WithHieDb )
61
+ import GHC (getInstancesForType )
60
62
import HieDb hiding (pointCommand ,
61
63
withHieDb )
62
64
import System.Directory (doesFileExist )
@@ -218,7 +220,8 @@ atPoint IdeOptions{} (HAR _ hf _ _ (kind :: HieKind hietype)) (DKMap dm km) env
218
220
hoverInfo :: HieAST hietype -> IO (Maybe Range , [T. Text ])
219
221
hoverInfo ast = do
220
222
prettyNames <- mapM prettyName filteredNames
221
- pure (Just range, prettyNames ++ pTypes)
223
+ instances <- catMaybes <$> mapM prettyInstances filteredNames
224
+ pure (Just range, prettyNames ++ pTypes ++ instances)
222
225
where
223
226
pTypes :: [T. Text ]
224
227
pTypes
@@ -306,6 +309,24 @@ atPoint IdeOptions{} (HAR _ hf _ _ (kind :: HieKind hietype)) (DKMap dm km) env
306
309
UnhelpfulLoc {} | isInternalName name || isSystemName name -> Nothing
307
310
_ -> Just $ " *Defined " <> printOutputable (pprNameDefnLoc name) <> " *"
308
311
312
+ prettyInstances :: (Either ModuleName Name , IdentifierDetails hietype ) -> IO (Maybe T. Text )
313
+ prettyInstances (Right n, _) =
314
+ fmap (wrapHaskell . T. unlines . fmap printOutputable) <$> instancesForName
315
+ where
316
+ instancesForName :: IO (Maybe [ClsInst ])
317
+ instancesForName = runMaybeT $ do
318
+ typ <- MaybeT . pure $ lookupNameEnv km n >>= tyThingToType
319
+ liftIO $ evalGhcEnv env $ getInstancesForType typ
320
+
321
+ tyThingToType :: TyThing -> Maybe Type
322
+ tyThingToType (AnId _) = Nothing
323
+ tyThingToType (ACoAxiom _) = Nothing
324
+ tyThingToType (AConLike cl) = case cl of
325
+ PatSynCon _ -> Nothing
326
+ RealDataCon dc -> Just $ mkTyConTy $ dataConTyCon dc
327
+ tyThingToType (ATyCon tc) = Just $ mkTyConTy tc
328
+ prettyInstances (Left _, _) = pure Nothing
329
+
309
330
typeLocationsAtPoint
310
331
:: forall m
311
332
. MonadIO m
0 commit comments