@@ -26,7 +26,6 @@ import qualified Data.Map as M
2626import Data.Maybe
2727import Data.Mod.Word
2828import Data.Row
29- import qualified Data.Set as S
3029import qualified Data.Text as T
3130import Development.IDE (Recorder , WithPriority ,
3231 usePropertyAction )
@@ -35,6 +34,7 @@ import Development.IDE.Core.PositionMapping
3534import Development.IDE.Core.RuleTypes
3635import Development.IDE.Core.Service
3736import Development.IDE.Core.Shake
37+ import qualified Development.IDE.GHC.Compat as Compat
3838import Development.IDE.GHC.Compat.Core
3939import Development.IDE.GHC.Compat.ExactPrint
4040import Development.IDE.GHC.Compat.Parser
@@ -236,12 +236,20 @@ handleGetHieAst state nfp =
236236-- | We don't want to rename in code generated by GHC as this gives false positives.
237237-- So we restrict the HIE file to remove all the generated code.
238238removeGenerated :: HieAstResult -> HieAstResult
239- removeGenerated HAR {.. } = HAR {hieAst = go hieAst, .. }
239+ removeGenerated HAR {.. } = HAR {hieAst = sourceOnlyAsts, refMap = sourceOnlyRefMap, .. }
240240 where
241- go :: HieASTs a -> HieASTs a
242- go hf =
243- HieASTs (fmap goAst (getAsts hf))
244- goAst (Node nsi sp xs) = Node (SourcedNodeInfo $ M. restrictKeys (getSourcedNodeInfo nsi) (S. singleton SourceInfo )) sp (map goAst xs)
241+ goAsts :: HieASTs a -> HieASTs a
242+ goAsts (HieASTs asts) = HieASTs (fmap goAst asts)
243+
244+ goAst :: HieAST a -> HieAST a
245+ goAst (Node (SourcedNodeInfo sniMap) sp children) =
246+ let sourceOnlyNodeInfos = SourcedNodeInfo $ M. delete GeneratedInfo sniMap
247+ in Node sourceOnlyNodeInfos sp $ map goAst children
248+
249+ sourceOnlyAsts = goAsts hieAst
250+ -- Also need to regenerate the RefMap, because the one in HAR
251+ -- is generated from HieASTs containing GeneratedInfo
252+ sourceOnlyRefMap = Compat. generateReferencesMap $ Compat. getAsts sourceOnlyAsts
245253
246254collectWith :: (Hashable a , Eq b ) => (a -> b ) -> HashSet a -> [(b , HashSet a )]
247255collectWith f = map (\ (a :| as) -> (f a, HS. fromList (a: as))) . groupWith f . HS. toList
0 commit comments