@@ -75,7 +75,6 @@ import GHC (AddEpAnn (Ad
7575 EpAnn (.. ),
7676 EpaLocation (.. ),
7777 LEpaComment )
78- import GHC.Exts (fromList )
7978import qualified GHC.LanguageExtensions as Lang
8079import Ide.Logger hiding
8180 (group )
@@ -189,18 +188,18 @@ extendImportHandler :: CommandFunction IdeState ExtendImport
189188extendImportHandler ideState _ edit@ ExtendImport {.. } = ExceptT $ do
190189 res <- liftIO $ runMaybeT $ extendImportHandler' ideState edit
191190 whenJust res $ \ (nfp, wedit@ WorkspaceEdit {_changes}) -> do
192- let (_, head -> TextEdit {_range}) = fromJust $ _changes >>= listToMaybe . M. toList
193- srcSpan = rangeToSrcSpan nfp _range
194- LSP. sendNotification SMethod_WindowShowMessage $
195- ShowMessageParams MessageType_Info $
196- " Import "
197- <> maybe (" ‘" <> newThing) (\ x -> " ‘" <> x <> " (" <> newThing <> " )" ) thingParent
198- <> " ’ from "
199- <> importName
200- <> " (at "
201- <> printOutputable srcSpan
202- <> " )"
203- void $ LSP. sendRequest SMethod_WorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing wedit) (\ _ -> pure () )
191+ whenJust (listToMaybe =<< listToMaybe . M. elems =<< _changes) $ \ TextEdit {_range} -> do
192+ let srcSpan = rangeToSrcSpan nfp _range
193+ LSP. sendNotification SMethod_WindowShowMessage $
194+ ShowMessageParams MessageType_Info $
195+ " Import "
196+ <> maybe (" ‘" <> newThing) (\ x -> " ‘" <> x <> " (" <> newThing <> " )" ) thingParent
197+ <> " ’ from "
198+ <> importName
199+ <> " (at "
200+ <> printOutputable srcSpan
201+ <> " )"
202+ void $ LSP. sendRequest SMethod_WorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing wedit) (\ _ -> pure () )
204203 return $ Right $ InR Null
205204
206205extendImportHandler' :: IdeState -> ExtendImport -> MaybeT IO (NormalizedFilePath , WorkspaceEdit )
@@ -223,8 +222,7 @@ extendImportHandler' ideState ExtendImport {..}
223222 case existingImport of
224223 Just imp -> do
225224 fmap (nfp,) $ liftEither $
226- rewriteToWEdit df doc
227- $
225+ rewriteToWEdit df doc $
228226 extendImport (T. unpack <$> thingParent) (T. unpack newThing) (makeDeltaAst imp)
229227
230228 Nothing -> do
@@ -235,7 +233,7 @@ extendImportHandler' ideState ExtendImport {..}
235233 Nothing -> newThing
236234 Just p -> p <> " (" <> newThing <> " )"
237235 t <- liftMaybe $ snd <$> newImportToEdit n ps (fromMaybe " " contents)
238- return (nfp, WorkspaceEdit {_changes= Just (GHC.Exts. fromList [( doc, [t]) ]), _documentChanges= Nothing , _changeAnnotations= Nothing })
236+ return (nfp, WorkspaceEdit {_changes= Just (M. singleton doc [t]), _documentChanges= Nothing , _changeAnnotations= Nothing })
239237 | otherwise =
240238 mzero
241239
@@ -609,7 +607,7 @@ suggestDeleteUnusedBinding
609607 let maybeIdx = findIndex (\ (L _ id ) -> isSameName id name) lnames
610608 in case maybeIdx of
611609 Nothing -> Nothing
612- Just _ | length lnames == 1 -> Just (getLoc $ reLoc $ head lnames , True )
610+ Just _ | [lname] <- lnames -> Just (getLoc $ reLoc lname , True )
613611 Just idx ->
614612 let targetLname = getLoc $ reLoc $ lnames !! idx
615613 startLoc = srcSpanStart targetLname
@@ -1052,7 +1050,7 @@ suggestImportDisambiguation df (Just txt) ps fileContents diag@Diagnostic {..}
10521050 parensed =
10531051 " (" `T.isPrefixOf` T. strip (textInRange _range txt)
10541052 -- > removeAllDuplicates [1, 1, 2, 3, 2] = [3]
1055- removeAllDuplicates = map head . filter ((== 1 ) <$> length ) . group . sort
1053+ removeAllDuplicates = map NE. head . filter ((== 1 ) . length ) . NE. group . sort
10561054 hasDuplicate xs = length xs /= length (S. fromList xs)
10571055 suggestions symbol mods local
10581056 | hasDuplicate mods = case mapM toModuleTarget (removeAllDuplicates mods) of
@@ -1290,7 +1288,7 @@ suggestImplicitParameter (L _ HsModule {hsmodDecls}) Diagnostic {_message, _rang
12901288 | otherwise = []
12911289
12921290findTypeSignatureName :: T. Text -> Maybe T. Text
1293- findTypeSignatureName t = matchRegexUnifySpaces t " ([^ ]+) :: " <&> head
1291+ findTypeSignatureName t = matchRegexUnifySpaces t " ([^ ]+) :: " >>= listToMaybe
12941292
12951293-- | Suggests a constraint for a type signature with any number of existing constraints.
12961294suggestFunctionConstraint :: DynFlags -> ParsedSource -> Diagnostic -> T. Text -> [(T. Text , Rewrite )]
@@ -1378,7 +1376,8 @@ removeRedundantConstraints df (makeDeltaAst -> L _ HsModule {hsmodDecls}) Diagno
13781376 & take 2
13791377 & mapMaybe ((`matchRegexUnifySpaces` " Redundant constraints?: (.+)" ) . T. strip)
13801378 & listToMaybe
1381- <&> (head >>> parseConstraints)
1379+ >>= listToMaybe
1380+ <&> parseConstraints
13821381
13831382 formatConstraints :: [T. Text ] -> T. Text
13841383 formatConstraints [] = " "
@@ -1658,7 +1657,7 @@ findPositionAfterModuleName ps hsmodName' = do
16581657#endif
16591658 EpAnn _ annsModule _ -> do
16601659 -- Find the first 'where'
1661- whereLocation <- fmap NE. head . NE. nonEmpty . mapMaybe filterWhere . am_main $ annsModule
1660+ whereLocation <- listToMaybe . mapMaybe filterWhere $ am_main annsModule
16621661 epaLocationToLine whereLocation
16631662 EpAnnNotUsed -> Nothing
16641663 filterWhere (AddEpAnn AnnWhere loc) = Just loc
0 commit comments