@@ -26,7 +26,6 @@ import qualified Data.Map as M
26
26
import Data.Maybe
27
27
import Data.Mod.Word
28
28
import Data.Row
29
- import qualified Data.Set as S
30
29
import qualified Data.Text as T
31
30
import Development.IDE (Recorder , WithPriority ,
32
31
usePropertyAction )
@@ -35,6 +34,7 @@ import Development.IDE.Core.PositionMapping
35
34
import Development.IDE.Core.RuleTypes
36
35
import Development.IDE.Core.Service
37
36
import Development.IDE.Core.Shake
37
+ import qualified Development.IDE.GHC.Compat as Compat
38
38
import Development.IDE.GHC.Compat.Core
39
39
import Development.IDE.GHC.Compat.ExactPrint
40
40
import Development.IDE.GHC.Compat.Parser
@@ -236,12 +236,20 @@ handleGetHieAst state nfp =
236
236
-- | We don't want to rename in code generated by GHC as this gives false positives.
237
237
-- So we restrict the HIE file to remove all the generated code.
238
238
removeGenerated :: HieAstResult -> HieAstResult
239
- removeGenerated HAR {.. } = HAR {hieAst = go hieAst, .. }
239
+ removeGenerated HAR {.. } = HAR {hieAst = sourceOnlyAsts, refMap = sourceOnlyRefMap, .. }
240
240
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
245
253
246
254
collectWith :: (Hashable a , Eq b ) => (a -> b ) -> HashSet a -> [(b , HashSet a )]
247
255
collectWith f = map (\ (a :| as) -> (f a, HS. fromList (a: as))) . groupWith f . HS. toList
0 commit comments