@@ -16,6 +16,7 @@ import Control.Monad.IO.Class (MonadIO, liftIO)
16
16
import Control.Monad.Trans.Class (lift )
17
17
import Data.Bifunctor (first )
18
18
import Data.Foldable (fold )
19
+ import Data.Either (rights )
19
20
import Data.Generics
20
21
import Data.Hashable
21
22
import Data.HashSet (HashSet )
@@ -35,6 +36,7 @@ import Development.IDE.Core.PositionMapping
35
36
import Development.IDE.Core.RuleTypes
36
37
import Development.IDE.Core.Service
37
38
import Development.IDE.Core.Shake
39
+ import Development.IDE.GHC.Compat
38
40
import Development.IDE.GHC.Compat.Core
39
41
import Development.IDE.GHC.Compat.ExactPrint
40
42
import Development.IDE.GHC.Compat.Parser
@@ -212,26 +214,26 @@ refsAtName state nfp name = do
212
214
)
213
215
pure $ nameLocs name ast ++ dbRefs
214
216
215
- nameLocs :: Name -> ( HieAstResult , PositionMapping ) -> [Location ]
216
- nameLocs name (HAR _ _ rm _ _, pm ) =
217
- concatMap (mapMaybe (toCurrentLocation pm . realSrcSpanToLocation . fst ))
217
+ nameLocs :: Name -> HieAstResult -> [Location ]
218
+ nameLocs name (HAR _ _ rm _ _) =
219
+ concatMap (map ( realSrcSpanToLocation . fst ))
218
220
(M. lookup (Right name) rm)
219
221
220
222
---------------------------------------------------------------------------------------------------
221
223
-- Util
222
224
223
225
getNamesAtPos :: MonadIO m => IdeState -> NormalizedFilePath -> Position -> ExceptT PluginError m [Name ]
224
226
getNamesAtPos state nfp pos = do
225
- ( HAR {hieAst}, pm) <- handleGetHieAst state nfp
226
- pure $ getNamesAtPoint hieAst pos pm
227
+ HAR {hieAst} <- handleGetHieAst state nfp
228
+ pure $ getNamesAtPoint' hieAst pos
227
229
228
230
handleGetHieAst ::
229
231
MonadIO m =>
230
232
IdeState ->
231
233
NormalizedFilePath ->
232
- ExceptT PluginError m ( HieAstResult , PositionMapping )
234
+ ExceptT PluginError m HieAstResult
233
235
handleGetHieAst state nfp =
234
- fmap (first removeGenerated) $ runActionE " Rename.GetHieAst" state $ useWithStaleE GetHieAst nfp
236
+ fmap removeGenerated $ runActionE " Rename.GetHieAst" state $ useE GetHieAst nfp
235
237
236
238
-- | We don't want to rename in code generated by GHC as this gives false positives.
237
239
-- So we restrict the HIE file to remove all the generated code.
@@ -246,6 +248,11 @@ removeGenerated HAR{..} = HAR{hieAst = go hieAst,..}
246
248
collectWith :: (Hashable a , Eq b ) => (a -> b ) -> HashSet a -> [(b , HashSet a )]
247
249
collectWith f = map (\ (a :| as) -> (f a, HS. fromList (a: as))) . groupWith f . HS. toList
248
250
251
+ -- | A variant 'getNamesAtPoint' that does not expect a 'PositionMapping'
252
+ getNamesAtPoint' :: HieASTs a -> Position -> [Name ]
253
+ getNamesAtPoint' hf pos =
254
+ concat $ pointCommand hf pos (rights . M. keys . getNodeIds)
255
+
249
256
locToUri :: Location -> Uri
250
257
locToUri (Location uri _) = uri
251
258
0 commit comments