@@ -138,13 +138,15 @@ isRecFieldRef _ = False
138138
139139produceDecl
140140 :: Glean. NewFact m
141- => Hs. Name
141+ => Map (Glean. IdOf Hs. Name ) Hs. SigDecl
142+ -> Hs. Name
142143 -> Maybe Hs. Type
143144 -> ContextInfo
144145 -> m ()
145- produceDecl name maybeTy ctx = case ctx of
146+ produceDecl sigMap name maybeTy ctx = case ctx of
146147 ValBind RegularBind _ _ ->
147- Glean. makeFact_ @ Hs. ValBind $ Hs. ValBind_key name maybeTy
148+ Glean. makeFact_ @ Hs. ValBind $
149+ Hs. ValBind_key name maybeTy (Map. lookup (Glean. getId name) sigMap)
148150 Decl FamDec _ ->
149151 Glean. makeFact_ @ Hs. TypeFamilyDecl $ Hs. TypeFamilyDecl_key name
150152 Decl SynDec _ ->
@@ -167,30 +169,40 @@ produceDecl name maybeTy ctx = case ctx of
167169
168170produceDeclInfo
169171 :: Glean. NewFact m
170- => Map GHC. Name Hs. Name
172+ => Src. File
173+ -> (GHC. RealSrcSpan -> Src. ByteSpan )
174+ -> Map GHC. Name Hs. Name
171175 -> Map GHC. Name DeclInfo
172- -> m ()
173- produceDeclInfo nameMap declInfoMap =
174- forM_ (Map. toList declInfoMap) $ \ (name, info) ->
175- whenJust (Map. lookup name nameMap) $ \ hsName ->
176- case info of
177- DataDecl { dataDeclConstrs = cs } -> do
178- cons <- forM cs $ \ (ConstrInfo cName fields) -> do
179- forM (Map. lookup cName nameMap) $ \ hsCName -> do
180- fNames <- forM (mapMaybe (`Map.lookup` nameMap) fields) $ \ fName ->
181- Glean. makeFact @ Hs. RecordFieldDecl $
182- Hs. RecordFieldDecl_key fName hsCName
183- Glean. makeFact @ Hs. ConstrDecl $
184- Hs. ConstrDecl_key hsCName hsName fNames
185- Glean. makeFact_ @ Hs. DataDecl $
186- Hs. DataDecl_key hsName (catMaybes cons)
187-
188- ClassDecl { classDeclMethods = ms } -> do
189- mNames <- forM (mapMaybe (`Map.lookup` nameMap) ms) $ \ mName ->
190- Glean. makeFact @ Hs. MethDecl $
191- Hs. MethDecl_key mName hsName
192- Glean. makeFact_ @ Hs. ClassDecl $
193- Hs. ClassDecl_key hsName mNames
176+ -> m (Map (Glean. IdOf Hs. Name ) Hs. SigDecl )
177+ produceDeclInfo fileFact toByteSpan nameMap declInfoMap =
178+ fmap (Map. fromList . catMaybes) $
179+ forM (Map. toList declInfoMap) $ \ (name, info) ->
180+ flip (maybe (return Nothing )) (Map. lookup name nameMap) $ \ hsName ->
181+ case info of
182+ SigDecl { sigDeclSpan = span } -> do
183+ decl <- Glean. makeFact @ Hs. SigDecl $
184+ Hs. SigDecl_key hsName (
185+ Src. FileLocation fileFact (toByteSpan span ))
186+ return (Just (Glean. getId hsName, decl))
187+ DataDecl { dataDeclConstrs = cs } -> do
188+ cons <- forM cs $ \ (ConstrInfo cName fields) -> do
189+ forM (Map. lookup cName nameMap) $ \ hsCName -> do
190+ fNames <- forM (mapMaybe (`Map.lookup` nameMap) fields) $
191+ \ fName ->
192+ Glean. makeFact @ Hs. RecordFieldDecl $
193+ Hs. RecordFieldDecl_key fName hsCName
194+ Glean. makeFact @ Hs. ConstrDecl $
195+ Hs. ConstrDecl_key hsCName hsName fNames
196+ Glean. makeFact_ @ Hs. DataDecl $
197+ Hs. DataDecl_key hsName (catMaybes cons)
198+ return Nothing
199+ ClassDecl { classDeclMethods = ms } -> do
200+ mNames <- forM (mapMaybe (`Map.lookup` nameMap) ms) $ \ mName ->
201+ Glean. makeFact @ Hs. MethDecl $
202+ Hs. MethDecl_key mName hsName
203+ Glean. makeFact_ @ Hs. ClassDecl $
204+ Hs. ClassDecl_key hsName mNames
205+ return Nothing
194206
195207nat :: Integral a => a -> Glean. Nat
196208nat = Glean. toNat . fromIntegral
@@ -338,8 +350,6 @@ indexHieFile writer srcPaths path hie = do
338350 GHC.occNameString (nameOccName name) <> ": " <>
339351 show (ppr sp)) $ return ()
340352 -}
341- let ty = identType dets >>= \ ix -> IntMap. lookup ix typeMap
342- mapM_ (produceDecl namefact ty) (Set. toList (identInfo dets))
343353 return $ Just (name, namefact)
344354 | otherwise -> return Nothing
345355
@@ -348,6 +358,15 @@ indexHieFile writer srcPaths path hie = do
348358 nameMap :: Map GHC. Name Hs. Name
349359 nameMap = Map. fromList names
350360
361+ sigMap <- produceDeclInfo filefact toByteSpan nameMap declInfo
362+
363+ forM_ allIds $ \ (ident, (_, dets)) -> if
364+ | Right name <- ident
365+ , Just namefact <- Map. lookup name nameMap -> do
366+ let ty = identType dets >>= \ ix -> IntMap. lookup ix typeMap
367+ mapM_ (produceDecl sigMap namefact ty) (Set. toList (identInfo dets))
368+ | otherwise -> return ()
369+
351370 eNames <- forM (concatMap GHC. availNames (hie_exports hie)) $ \ name ->
352371 case Map. lookup name nameMap of
353372 Just hsName -> return $ Just hsName
@@ -357,8 +376,6 @@ indexHieFile writer srcPaths path hie = do
357376 mod <- if m == smod then return modfact else mkModule m
358377 Just <$> mkName name mod (Hs. NameSort_external def)
359378
360- produceDeclInfo nameMap declInfo
361-
362379 Glean. makeFact_ @ Hs. ModuleDeclarations $ Hs. ModuleDeclarations_key
363380 modfact (map snd names) (catMaybes eNames)
364381
@@ -508,6 +525,9 @@ data DeclInfo
508525 | ClassDecl {
509526 classDeclMethods :: [GHC. Name ]
510527 }
528+ | SigDecl {
529+ sigDeclSpan :: GHC. RealSrcSpan
530+ }
511531
512532data ConstrInfo =
513533 ConstrInfo {
@@ -539,6 +559,9 @@ getDeclInfos node = snd $ State.runState (go node) Map.empty
539559 | isClassDecl nodeInfo,
540560 [name] <- findIdent classDeclCtx nodeInfo node =
541561 Just (name, ClassDecl { classDeclMethods = findMethods node })
562+ | isTypeSig nodeInfo,
563+ [name] <- findIdent tyDeclCtx nodeInfo node =
564+ Just (name, SigDecl { sigDeclSpan = nodeSpan node })
542565 | otherwise =
543566 Nothing
544567
@@ -547,6 +570,7 @@ getDeclInfos node = snd $ State.runState (go node) Map.empty
547570 concatMap (namesWithContext ctx) $
548571 map nodeIdentifiers (ni : map getNodeInfo nodeChildren)
549572
573+ isTypeSig = any (== typeSigAnnot) . nodeAnnotations
550574 isDataDecl = any (== dataDeclAnnot) . nodeAnnotations
551575 isConstrDecl = any (`elem` [constrAnnot, constrGadtAnnot]) . nodeAnnotations
552576 isClassDecl = any (== classDeclAnnot) . nodeAnnotations
@@ -604,6 +628,10 @@ recFieldDeclCtx :: ContextInfo -> Bool
604628recFieldDeclCtx (RecField r _) = not (isRecFieldRef r)
605629recFieldDeclCtx _ = False
606630
631+ tyDeclCtx :: ContextInfo -> Bool
632+ tyDeclCtx TyDecl = True
633+ tyDeclCtx _ = False
634+
607635classDeclCtx :: ContextInfo -> Bool
608636classDeclCtx (Decl ClassDec _) = True
609637classDeclCtx _ = False
@@ -612,6 +640,9 @@ classTyDeclCtx :: ContextInfo -> Bool
612640classTyDeclCtx (ClassTyDecl _) = True
613641classTyDeclCtx _ = False
614642
643+ typeSigAnnot :: NodeAnnotation
644+ typeSigAnnot = NodeAnnotation " TypeSig" " Sig"
645+
615646dataDeclAnnot :: NodeAnnotation
616647dataDeclAnnot = NodeAnnotation " DataDecl" " TyClDecl"
617648
0 commit comments