Skip to content

Commit 299b0d3

Browse files
committed
Fix it
1 parent 4fb8e57 commit 299b0d3

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
@@ -25,7 +25,6 @@ import Data.List.NonEmpty (NonEmpty ((:|)),
2525
import qualified Data.Map as M
2626
import Data.Maybe
2727
import Data.Mod.Word
28-
import qualified Data.Set as S
2928
import qualified Data.Text as T
3029
import Development.IDE (Recorder, WithPriority,
3130
usePropertyAction)
@@ -34,6 +33,7 @@ import Development.IDE.Core.PositionMapping
3433
import Development.IDE.Core.RuleTypes
3534
import Development.IDE.Core.Service
3635
import Development.IDE.Core.Shake
36+
import qualified Development.IDE.GHC.Compat as Compat
3737
import Development.IDE.GHC.Compat.Core
3838
import Development.IDE.GHC.Compat.ExactPrint
3939
import Development.IDE.GHC.Compat.Parser
@@ -212,12 +212,20 @@ handleGetHieAst state nfp =
212212
-- | We don't want to rename in code generated by GHC as this gives false positives.
213213
-- So we restrict the HIE file to remove all the generated code.
214214
removeGenerated :: HieAstResult -> HieAstResult
215-
removeGenerated HAR{..} = HAR{hieAst = go hieAst,..}
215+
removeGenerated HAR{..} = HAR{hieAst = sourceOnlyAsts, refMap = sourceOnlyRefMap, ..}
216216
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
221229

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

0 commit comments

Comments
 (0)