@@ -25,6 +25,7 @@ import Control.Monad.IO.Class
2525import Control.Monad.Trans.Class
2626import Control.Monad.Trans.Except
2727import Data.Bifunctor (first )
28+ import Data.Either
2829import Data.Generics
2930import Data.Hashable
3031import Data.HashSet (HashSet )
@@ -42,6 +43,7 @@ import Development.IDE.Core.PositionMapping
4243import Development.IDE.Core.RuleTypes
4344import Development.IDE.Core.Service
4445import Development.IDE.Core.Shake
46+ import Development.IDE.GHC.Compat
4547import Development.IDE.GHC.Compat.Core
4648import Development.IDE.GHC.Compat.ExactPrint
4749import Development.IDE.GHC.Compat.Parser
@@ -210,26 +212,26 @@ refsAtName state nfp name = do
210212 )
211213 pure $ nameLocs name ast ++ dbRefs
212214
213- nameLocs :: Name -> ( HieAstResult , PositionMapping ) -> [Location ]
214- nameLocs name (HAR _ _ rm _ _, pm ) =
215- mapMaybe (toCurrentLocation pm . realSrcSpanToLocation . fst )
216- (concat $ M. lookup (Right name) rm)
215+ nameLocs :: Name -> HieAstResult -> [Location ]
216+ nameLocs name (HAR _ _ rm _ _) =
217+ map ( realSrcSpanToLocation . fst )
218+ (concat $ M. lookup (Right name) rm)
217219
218220---------------------------------------------------------------------------------------------------
219221-- Util
220222
221223getNamesAtPos :: MonadIO m => IdeState -> NormalizedFilePath -> Position -> ExceptT PluginError m [Name ]
222224getNamesAtPos state nfp pos = do
223- ( HAR {hieAst}, pm) <- handleGetHieAst state nfp
224- pure $ getNamesAtPoint hieAst pos pm
225+ HAR {hieAst} <- handleGetHieAst state nfp
226+ pure $ getNamesAtPoint' hieAst pos
225227
226228handleGetHieAst ::
227229 MonadIO m =>
228230 IdeState ->
229231 NormalizedFilePath ->
230- ExceptT PluginError m ( HieAstResult , PositionMapping )
232+ ExceptT PluginError m HieAstResult
231233handleGetHieAst state nfp =
232- fmap (first removeGenerated) $ runActionE " Rename.GetHieAst" state $ useWithStaleE GetHieAst nfp
234+ fmap removeGenerated $ runActionE " Rename.GetHieAst" state $ useE GetHieAst nfp
233235
234236-- | We don't want to rename in code generated by GHC as this gives false positives.
235237-- So we restrict the HIE file to remove all the generated code.
@@ -245,6 +247,11 @@ removeGenerated HAR{..} = HAR{hieAst = go hieAst,..}
245247 hf
246248#endif
247249
250+ -- | A variant 'getNamesAtPoint' that does not expect a 'PositionMapping'
251+ getNamesAtPoint' :: HieASTs a -> Position -> [Name ]
252+ getNamesAtPoint' hf pos =
253+ concat $ pointCommand hf pos (rights . M. keys . getNodeIds)
254+
248255-- head is safe since groups are non-empty
249256collectWith :: (Hashable a , Eq a , Eq b ) => (a -> b ) -> HashSet a -> [(b , HashSet a )]
250257collectWith f = map (\ a -> (f $ head a, HS. fromList a)) . groupOn f . HS. toList
0 commit comments