Skip to content

Commit db9fc60

Browse files
committed
Fix it
1 parent 14ebf76 commit db9fc60

File tree

1 file changed

+13
-5
lines changed
  • plugins/hls-rename-plugin/src/Ide/Plugin

1 file changed

+13
-5
lines changed

plugins/hls-rename-plugin/src/Ide/Plugin/Rename.hs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,20 @@ handleGetHieAst state nfp =
232232
-- | We don't want to rename in code generated by GHC as this gives false positives.
233233
-- So we restrict the HIE file to remove all the generated code.
234234
removeGenerated :: HieAstResult -> HieAstResult
235-
removeGenerated HAR{..} = HAR{hieAst = go hieAst,..}
235+
removeGenerated HAR{..} = HAR{hieAst = sourceOnlyAsts, refMap = sourceOnlyRefMap, ..}
236236
where
237-
go :: HieASTs a -> HieASTs a
238-
go hf =
239-
HieASTs (fmap goAst (getAsts hf))
240-
goAst (Node nsi sp xs) = Node (SourcedNodeInfo $ M.restrictKeys (getSourcedNodeInfo nsi) (S.singleton SourceInfo)) sp (map goAst xs)
237+
goAsts :: HieASTs a -> HieASTs a
238+
goAsts (HieASTs asts) = HieASTs (fmap goAst asts)
239+
240+
goAst :: HieAST a -> HieAST a
241+
goAst (Node (SourcedNodeInfo sniMap) sp children) =
242+
let sourceOnlyNodeInfos = SourcedNodeInfo $ M.delete GeneratedInfo sniMap
243+
in Node sourceOnlyNodeInfos sp $ map goAst children
244+
245+
sourceOnlyAsts = goAsts hieAst
246+
-- Also need to regenerate the RefMap, because the one in HAR
247+
-- is generated from HieASTs containing GeneratedInfo
248+
sourceOnlyRefMap = Compat.generateReferencesMap $ Compat.getAsts sourceOnlyAsts
241249

242250
collectWith :: (Hashable a, Eq b) => (a -> b) -> HashSet a -> [(b, HashSet a)]
243251
collectWith f = map (\(a :| as) -> (f a, HS.fromList (a:as))) . groupWith f . HS.toList

0 commit comments

Comments
 (0)