@@ -15,11 +15,13 @@ import Control.Monad.Except (ExceptT, throwError)
15
15
import Control.Monad.IO.Class (MonadIO , liftIO )
16
16
import Control.Monad.Trans.Class (lift )
17
17
import Data.Bifunctor (first )
18
+ import Data.Foldable (fold )
18
19
import Data.Generics
19
20
import Data.Hashable
20
21
import Data.HashSet (HashSet )
21
22
import qualified Data.HashSet as HS
22
- import Data.List.Extra hiding (length )
23
+ import Data.List.NonEmpty (NonEmpty ((:|) ),
24
+ groupWith )
23
25
import qualified Data.Map as M
24
26
import Data.Maybe
25
27
import Data.Mod.Word
@@ -62,7 +64,7 @@ descriptor recorder pluginId = mkExactprintPluginDescriptor recorder $ (defaultP
62
64
}
63
65
64
66
renameProvider :: PluginMethodHandler IdeState Method_TextDocumentRename
65
- renameProvider state pluginId (RenameParams _prog (TextDocumentIdentifier uri) pos newNameText) = do
67
+ renameProvider state pluginId (RenameParams _prog (TextDocumentIdentifier uri) pos newNameText) = do
66
68
nfp <- getNormalizedFilePathE uri
67
69
directOldNames <- getNamesAtPos state nfp pos
68
70
directRefs <- concat <$> mapM (refsAtName state nfp) directOldNames
@@ -71,8 +73,8 @@ renameProvider state pluginId (RenameParams _prog (TextDocumentIdentifier uri) p
71
73
indirect references through punned names. To find the transitive closure, we do a pass of
72
74
the direct references to find the references for any punned names.
73
75
See the `IndirectPuns` test for an example. -}
74
- indirectOldNames <- concat . filter notNull <$>
75
- mapM (uncurry (getNamesAtPos state)) (mapMaybe locToFilePos directRefs)
76
+ indirectOldNames <- concat . filter (( > 1 ) . length ) <$>
77
+ ( mapM (uncurry (getNamesAtPos state)) =<< mapM locToFilePos directRefs)
76
78
let oldNames = filter matchesDirect indirectOldNames ++ directOldNames
77
79
matchesDirect n = occNameFS (nameOccName n) `elem` directFS
78
80
where
@@ -91,7 +93,7 @@ renameProvider state pluginId (RenameParams _prog (TextDocumentIdentifier uri) p
91
93
verTxtDocId <- lift $ getVersionedTextDoc (TextDocumentIdentifier uri)
92
94
getSrcEdit state verTxtDocId (replaceRefs newName locations)
93
95
fileEdits <- mapM getFileEdit filesRefs
94
- pure $ InL $ foldl' (<>) mempty fileEdits
96
+ pure $ InL $ fold fileEdits
95
97
96
98
-- | Limit renaming across modules.
97
99
failWhenImportOrExport ::
@@ -217,9 +219,8 @@ removeGenerated HAR{..} = HAR{hieAst = go hieAst,..}
217
219
HieASTs (fmap goAst (getAsts hf))
218
220
goAst (Node nsi sp xs) = Node (SourcedNodeInfo $ M. restrictKeys (getSourcedNodeInfo nsi) (S. singleton SourceInfo )) sp (map goAst xs)
219
221
220
- -- head is safe since groups are non-empty
221
222
collectWith :: (Hashable a , Eq b ) => (a -> b ) -> HashSet a -> [(b , HashSet a )]
222
- collectWith f = map (\ a -> (f $ head a, HS. fromList a)) . groupOn f . HS. toList
223
+ collectWith f = map (\ (a :| as) -> (f a, HS. fromList (a : as))) . groupWith f . HS. toList
223
224
224
225
locToUri :: Location -> Uri
225
226
locToUri (Location uri _) = uri
@@ -230,10 +231,8 @@ unsafeSrcSpanToLoc srcSpan =
230
231
Nothing -> error " Invalid conversion from UnhelpfulSpan to Location"
231
232
Just location -> location
232
233
233
- locToFilePos :: Location -> Maybe (NormalizedFilePath , Position )
234
- locToFilePos (Location uri (Range pos _)) = (,pos) <$> nfp
235
- where
236
- nfp = uriToNormalizedFilePath $ toNormalizedUri uri
234
+ locToFilePos :: Monad m => Location -> ExceptT PluginError m (NormalizedFilePath , Position )
235
+ locToFilePos (Location uri (Range pos _)) = (,pos) <$> getNormalizedFilePathE uri
237
236
238
237
replaceModName :: Name -> Maybe ModuleName -> Module
239
238
replaceModName name mbModName =
0 commit comments