@@ -25,7 +25,6 @@ import Data.List.NonEmpty (NonEmpty ((:|)),
25
25
import qualified Data.Map as M
26
26
import Data.Maybe
27
27
import Data.Mod.Word
28
- import qualified Data.Set as S
29
28
import qualified Data.Text as T
30
29
import Development.IDE (Recorder , WithPriority ,
31
30
usePropertyAction )
@@ -34,6 +33,7 @@ import Development.IDE.Core.PositionMapping
34
33
import Development.IDE.Core.RuleTypes
35
34
import Development.IDE.Core.Service
36
35
import Development.IDE.Core.Shake
36
+ import qualified Development.IDE.GHC.Compat as Compat
37
37
import Development.IDE.GHC.Compat.Core
38
38
import Development.IDE.GHC.Compat.ExactPrint
39
39
import Development.IDE.GHC.Compat.Parser
@@ -212,12 +212,20 @@ handleGetHieAst state nfp =
212
212
-- | We don't want to rename in code generated by GHC as this gives false positives.
213
213
-- So we restrict the HIE file to remove all the generated code.
214
214
removeGenerated :: HieAstResult -> HieAstResult
215
- removeGenerated HAR {.. } = HAR {hieAst = go hieAst, .. }
215
+ removeGenerated HAR {.. } = HAR {hieAst = sourceOnlyAsts, refMap = sourceOnlyRefMap, .. }
216
216
where
217
- go :: HieASTs a -> HieASTs a
218
- go hf =
219
- HieASTs (fmap goAst (getAsts hf))
220
- goAst (Node nsi sp xs) = Node (SourcedNodeInfo $ M. restrictKeys (getSourcedNodeInfo nsi) (S. singleton SourceInfo )) sp (map goAst xs)
217
+ goAsts :: HieASTs a -> HieASTs a
218
+ goAsts (HieASTs asts) = HieASTs (fmap goAst asts)
219
+
220
+ goAst :: HieAST a -> HieAST a
221
+ goAst (Node (SourcedNodeInfo sniMap) sp children) =
222
+ let sourceOnlyNodeInfos = SourcedNodeInfo $ M. delete GeneratedInfo sniMap
223
+ in Node sourceOnlyNodeInfos sp $ map goAst children
224
+
225
+ sourceOnlyAsts = goAsts hieAst
226
+ -- Also need to regenerate the RefMap, because the one in HAR
227
+ -- is generated from HieASTs containing GeneratedInfo
228
+ sourceOnlyRefMap = Compat. generateReferencesMap $ Compat. getAsts sourceOnlyAsts
221
229
222
230
collectWith :: (Hashable a , Eq b ) => (a -> b ) -> HashSet a -> [(b , HashSet a )]
223
231
collectWith f = map (\ (a :| as) -> (f a, HS. fromList (a: as))) . groupWith f . HS. toList
0 commit comments