@@ -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 )
@@ -52,7 +51,6 @@ import Ide.Types
52
51
import qualified Language.LSP.Protocol.Lens as L
53
52
import Language.LSP.Protocol.Message
54
53
import Language.LSP.Protocol.Types
55
- import Data.List
56
54
57
55
instance Hashable (Mod a ) where hash n = hash (unMod n)
58
56
@@ -103,7 +101,6 @@ renameProvider state pluginId (RenameParams _prog (TextDocumentIdentifier uri) p
103
101
[] -> throwError $ PluginInvalidParams " No symbol to rename at given position"
104
102
_ -> do
105
103
refs <- HS. fromList . concat <$> mapM (refsAtName state nfp) oldNames
106
-
107
104
-- Validate rename
108
105
crossModuleEnabled <- liftIO $ runAction " rename: config" state $ usePropertyAction # crossModule pluginId properties
109
106
unless crossModuleEnabled $ failWhenImportOrExport state nfp refs oldNames
@@ -198,22 +195,19 @@ refsAtName state nfp name = do
198
195
ast <- handleGetHieAst state nfp
199
196
dbRefs <- case nameModule_maybe name of
200
197
Nothing -> pure []
201
- Just mod -> liftIO $ mapMaybe rowToLoc <$> withHieDb (\ hieDb -> do
198
+ Just mod -> liftIO $ mapMaybe rowToLoc <$> withHieDb (\ hieDb ->
202
199
-- GHC inserts `Use`s of record constructor everywhere where its record selectors are used,
203
200
-- which leads to fields being renamed whenever corresponding constructor is renamed.
204
201
-- see https://github.com/haskell/haskell-language-server/issues/2915
205
202
-- To work around this, we filter out compiler-generated references.
206
-
207
- xs <- findReferences
203
+ filter ( \ (refRow HieDb. :. _) -> refIsGenerated refRow) <$>
204
+ findReferences
208
205
hieDb
209
206
True
210
207
(nameOccName name)
211
208
(Just $ moduleName mod )
212
209
(Just $ moduleUnit mod )
213
210
[fromNormalizedFilePath nfp]
214
- let (gen,notGen) = partition (\ (refRow HieDb. :. _) -> refIsGenerated refRow) xs
215
- putStrLn $ " Found " ++ show (length xs) ++ " references in HieDb: " ++ show (length xs) ++ " , of which " ++ show (length gen) ++ " are generated"
216
- pure notGen
217
211
)
218
212
pure $ nameLocs name ast ++ dbRefs
219
213
@@ -244,12 +238,21 @@ handleGetHieAst state nfp =
244
238
-- | We don't want to rename in code generated by GHC as this gives false positives.
245
239
-- So we restrict the HIE file to remove all the generated code.
246
240
removeGenerated :: HieAstResult -> HieAstResult
247
- removeGenerated HAR {.. } = HAR {hieAst = go hieAst,.. }
241
+ removeGenerated HAR {.. } =
242
+ HAR {hieAst = sourceOnlyAsts, refMap = sourceOnlyRefMap, .. }
248
243
where
249
- go :: HieASTs a -> HieASTs a
250
- go hf =
251
- HieASTs (fmap goAst (getAsts hf))
252
- goAst (Node nsi sp xs) = Node (SourcedNodeInfo $ M. restrictKeys (getSourcedNodeInfo nsi) (S. singleton SourceInfo )) sp (map goAst xs)
244
+ goAsts :: HieASTs a -> HieASTs a
245
+ goAsts (HieASTs asts) = HieASTs (fmap goAst asts)
246
+
247
+ goAst :: HieAST a -> HieAST a
248
+ goAst (Node (SourcedNodeInfo sniMap) sp children) =
249
+ let sourceOnlyNodeInfos = SourcedNodeInfo $ M. delete GeneratedInfo sniMap
250
+ in Node sourceOnlyNodeInfos sp $ map goAst children
251
+
252
+ sourceOnlyAsts = goAsts hieAst
253
+ -- Also need to regenerate the RefMap, because the one in HAR
254
+ -- is generated from HieASTs containing GeneratedInfo
255
+ sourceOnlyRefMap = generateReferencesMap $ getAsts sourceOnlyAsts
253
256
254
257
collectWith :: (Hashable a , Eq b ) => (a -> b ) -> HashSet a -> [(b , HashSet a )]
255
258
collectWith f = map (\ (a :| as) -> (f a, HS. fromList (a: as))) . groupWith f . HS. toList
0 commit comments