@@ -604,6 +604,7 @@ suggestDeleteUnusedBinding
604604 in ([(" Delete ‘" <> name <> " ’" , edits) | not (null edits)])
605605 | otherwise = []
606606 where
607+ hsmodSigs = [L l sig | L l (SigD _ sig) <- hsmodDecls]
607608 relatedRanges indexedContent name =
608609 concatMap (findRelatedSpans indexedContent name) hsmodDecls
609610 toRange = realSrcSpanToRange
@@ -614,11 +615,8 @@ suggestDeleteUnusedBinding
614615 (L (EpAnn (EpaSpan (RealSrcSpan l _)) _ _) (ValD _ (extractNameAndMatchesFromFunBind -> Just (lname, matches))))
615616 -> case lname of
616617 (L nLoc _name) | isTheBinding nLoc ->
617- let findSig (L (EpAnn (EpaSpan (RealSrcSpan l _)) _ c) (SigD _ sig)) = findRelatedSigSpan indexedContent name l c sig
618- findSig _ = []
619- in
620- extendForSpaces indexedContent (toRange l) :
621- concatMap findSig hsmodDecls
618+ extendForSpaces indexedContent (toRange l)
619+ : concatMap (findRelatedSigSpan' indexedContent name) hsmodSigs
622620 _ -> concatMap (findRelatedSpanForMatch indexedContent name) matches
623621 _ -> []
624622
@@ -632,13 +630,14 @@ suggestDeleteUnusedBinding
632630 } = Just (reLoc lname, matches)
633631 extractNameAndMatchesFromFunBind _ = Nothing
634632
635- findRelatedSigSpan :: PositionIndexedString -> String -> RealSrcSpan -> EpAnnComments -> Sig GhcPs -> [Range ]
636- findRelatedSigSpan indexedContent name l c sig =
637- let maybeSpan = findRelatedSigSpan1 name sig
638- in case maybeSpan of
639- Just (_span, True ) -> pure $ extendForSpaces indexedContent $ toRange $ l `withCommentSpan` c
640- Just (RealSrcSpan span _, False ) -> pure $ toRange span
641- _ -> []
633+ findRelatedSigSpan' :: PositionIndexedString -> String -> LSig GhcPs -> [Range ]
634+ findRelatedSigSpan' indexedContent name = \ case
635+ (L (EpAnn (EpaSpan (RealSrcSpan l _)) _ c) sig) ->
636+ case findRelatedSigSpan1 name sig of
637+ Just (_span, True ) -> [extendForSpaces indexedContent . toRange $ l `withCommentSpan` c]
638+ Just (RealSrcSpan span _, False ) -> [toRange span ]
639+ _ -> []
640+ _ -> []
642641
643642 -- Second of the tuple means there is only one match
644643 findRelatedSigSpan1 :: String -> Sig GhcPs -> Maybe (SrcSpan , Bool )
@@ -696,10 +695,8 @@ suggestDeleteUnusedBinding
696695 lsigs
697696 (L (locA -> (RealSrcSpan l _)) (extractNameAndMatchesFromFunBind -> Just (lname, matches))) =
698697 if isTheBinding (getLoc lname)
699- then
700- let findSig (L (EpAnn (EpaSpan (RealSrcSpan l _)) _ c) sig) = findRelatedSigSpan indexedContent name l c sig
701- findSig _ = []
702- in extendForSpaces indexedContent (toRange l) : concatMap findSig lsigs
698+ then extendForSpaces indexedContent (toRange l)
699+ : concatMap (findRelatedSigSpan' indexedContent name) lsigs
703700 else concatMap (findRelatedSpanForMatch indexedContent name) matches
704701 findRelatedSpanForHsBind _ _ _ _ = []
705702
0 commit comments