@@ -14,7 +14,7 @@ import Control.Monad
14
14
import Control.Monad.Except (ExceptT , throwError )
15
15
import Control.Monad.IO.Class (MonadIO , liftIO )
16
16
import Control.Monad.Trans.Class (lift )
17
- import Data.Bifunctor ( first )
17
+ import Data.Either ( rights )
18
18
import Data.Foldable (fold )
19
19
import Data.Generics
20
20
import Data.Hashable
@@ -31,14 +31,11 @@ import qualified Data.Text as T
31
31
import Development.IDE (Recorder , WithPriority ,
32
32
usePropertyAction )
33
33
import Development.IDE.Core.PluginUtils
34
- import Development.IDE.Core.PositionMapping
35
34
import Development.IDE.Core.RuleTypes
36
35
import Development.IDE.Core.Service
37
36
import Development.IDE.Core.Shake
38
- import Development.IDE.GHC.Compat.Core
37
+ import Development.IDE.GHC.Compat
39
38
import Development.IDE.GHC.Compat.ExactPrint
40
- import Development.IDE.GHC.Compat.Parser
41
- import Development.IDE.GHC.Compat.Units
42
39
import Development.IDE.GHC.Error
43
40
import Development.IDE.GHC.ExactPrint
44
41
import qualified Development.IDE.GHC.ExactPrint as E
@@ -212,26 +209,29 @@ refsAtName state nfp name = do
212
209
)
213
210
pure $ nameLocs name ast ++ dbRefs
214
211
215
- nameLocs :: Name -> ( HieAstResult , PositionMapping ) -> [Location ]
216
- nameLocs name (HAR _ _ rm _ _, pm ) =
217
- concatMap (mapMaybe (toCurrentLocation pm . realSrcSpanToLocation . fst ))
212
+ nameLocs :: Name -> HieAstResult -> [Location ]
213
+ nameLocs name (HAR _ _ rm _ _) =
214
+ concatMap (map ( realSrcSpanToLocation . fst ))
218
215
(M. lookup (Right name) rm)
219
216
220
217
---------------------------------------------------------------------------------------------------
221
218
-- Util
222
219
223
220
getNamesAtPos :: MonadIO m => IdeState -> NormalizedFilePath -> Position -> ExceptT PluginError m [Name ]
224
221
getNamesAtPos state nfp pos = do
225
- ( HAR {hieAst}, pm) <- handleGetHieAst state nfp
226
- pure $ getNamesAtPoint hieAst pos pm
222
+ HAR {hieAst} <- handleGetHieAst state nfp
223
+ pure $ getNamesAtPoint' hieAst pos
227
224
228
225
handleGetHieAst ::
229
226
MonadIO m =>
230
227
IdeState ->
231
228
NormalizedFilePath ->
232
- ExceptT PluginError m ( HieAstResult , PositionMapping )
229
+ ExceptT PluginError m HieAstResult
233
230
handleGetHieAst state nfp =
234
- fmap (first removeGenerated) $ runActionE " Rename.GetHieAst" state $ useWithStaleE GetHieAst nfp
231
+ -- We explicitly do not want to allow a stale version here - we only want to rename if
232
+ -- the module compiles, otherwise we can't guarantee that we'll rename everything,
233
+ -- which is bad (see https://github.com/haskell/haskell-language-server/issues/3799)
234
+ fmap removeGenerated $ runActionE " Rename.GetHieAst" state $ useE GetHieAst nfp
235
235
236
236
-- | We don't want to rename in code generated by GHC as this gives false positives.
237
237
-- So we restrict the HIE file to remove all the generated code.
@@ -246,6 +246,11 @@ removeGenerated HAR{..} = HAR{hieAst = go hieAst,..}
246
246
collectWith :: (Hashable a , Eq b ) => (a -> b ) -> HashSet a -> [(b , HashSet a )]
247
247
collectWith f = map (\ (a :| as) -> (f a, HS. fromList (a: as))) . groupWith f . HS. toList
248
248
249
+ -- | A variant 'getNamesAtPoint' that does not expect a 'PositionMapping'
250
+ getNamesAtPoint' :: HieASTs a -> Position -> [Name ]
251
+ getNamesAtPoint' hf pos =
252
+ concat $ pointCommand hf pos (rights . M. keys . getNodeIds)
253
+
249
254
locToUri :: Location -> Uri
250
255
locToUri (Location uri _) = uri
251
256
0 commit comments