@@ -25,6 +25,7 @@ import Control.Monad.IO.Class
25
25
import Control.Monad.Trans.Class
26
26
import Control.Monad.Trans.Except
27
27
import Data.Bifunctor (first )
28
+ import Data.Either
28
29
import Data.Generics
29
30
import Data.Hashable
30
31
import Data.HashSet (HashSet )
@@ -37,6 +38,7 @@ import qualified Data.Set as S
37
38
import qualified Data.Text as T
38
39
import Development.IDE (Recorder , WithPriority ,
39
40
usePropertyAction )
41
+ import Development.IDE.GHC.Compat
40
42
import Development.IDE.Core.PluginUtils
41
43
import Development.IDE.Core.PositionMapping
42
44
import Development.IDE.Core.RuleTypes
@@ -210,26 +212,26 @@ refsAtName state nfp name = do
210
212
)
211
213
pure $ nameLocs name ast ++ dbRefs
212
214
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)
217
219
218
220
---------------------------------------------------------------------------------------------------
219
221
-- Util
220
222
221
223
getNamesAtPos :: MonadIO m => IdeState -> NormalizedFilePath -> Position -> ExceptT PluginError m [Name ]
222
224
getNamesAtPos 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
225
227
226
228
handleGetHieAst ::
227
229
MonadIO m =>
228
230
IdeState ->
229
231
NormalizedFilePath ->
230
- ExceptT PluginError m ( HieAstResult , PositionMapping )
232
+ ExceptT PluginError m HieAstResult
231
233
handleGetHieAst state nfp =
232
- fmap (first removeGenerated) $ runActionE " Rename.GetHieAst" state $ useWithStaleE GetHieAst nfp
234
+ fmap removeGenerated $ runActionE " Rename.GetHieAst" state $ useE GetHieAst nfp
233
235
234
236
-- | We don't want to rename in code generated by GHC as this gives false positives.
235
237
-- So we restrict the HIE file to remove all the generated code.
@@ -245,6 +247,11 @@ removeGenerated HAR{..} = HAR{hieAst = go hieAst,..}
245
247
hf
246
248
#endif
247
249
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
+
248
255
-- head is safe since groups are non-empty
249
256
collectWith :: (Hashable a , Eq a , Eq b ) => (a -> b ) -> HashSet a -> [(b , HashSet a )]
250
257
collectWith f = map (\ a -> (f $ head a, HS. fromList a)) . groupOn f . HS. toList
0 commit comments