Skip to content

Commit 732f556

Browse files
committed
Fix it
1 parent bd1fe6e commit 732f556

File tree

1 file changed

+14
-6
lines changed
  • plugins/hls-rename-plugin/src/Ide/Plugin

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import qualified Data.Map as M
2626
import Data.Maybe
2727
import Data.Mod.Word
2828
import Data.Row
29-
import qualified Data.Set as S
3029
import qualified Data.Text as T
3130
import Development.IDE (Recorder, WithPriority,
3231
usePropertyAction)
@@ -35,6 +34,7 @@ import Development.IDE.Core.PositionMapping
3534
import Development.IDE.Core.RuleTypes
3635
import Development.IDE.Core.Service
3736
import Development.IDE.Core.Shake
37+
import qualified Development.IDE.GHC.Compat as Compat
3838
import Development.IDE.GHC.Compat.Core
3939
import Development.IDE.GHC.Compat.ExactPrint
4040
import 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.
238238
removeGenerated :: 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

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

0 commit comments

Comments
 (0)