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