Skip to content

Commit 25be42a

Browse files
committed
Collect records on lists instead of maybe
This way we don't need to switch back and forward between the two, and we can also return more than one match from inside a HsExpanded
1 parent 3270e7a commit 25be42a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

plugins/hls-overloaded-record-dot-plugin/src/Ide/Plugin/OverloadedRecordDot.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,27 +186,27 @@ convertRecSel se re =
186186
-- It's important that we use everthingBut here, because if we used everything we would
187187
-- get duplicates for every case that occures inside a HsExpanded expression.
188188
collectRecordSelectors :: GenericQ [RecordSelectorExpr]
189-
collectRecordSelectors = everythingBut (<>) (first maybeToList. ((Nothing, False) `mkQ` getRecSels))
189+
collectRecordSelectors = everythingBut (<>) (([], False) `mkQ` getRecSels)
190190

191-
getRecSels :: LHsExpr (GhcPass 'Renamed) -> (Maybe RecordSelectorExpr, Bool)
191+
getRecSels :: LHsExpr (GhcPass 'Renamed) -> ([RecordSelectorExpr], Bool)
192192
-- When we stumble upon an occurance of HsExpanded, we only want to follow one branch
193-
-- we do this here, by explicitly returning an occurance from traversing the original branch,
193+
-- we do this here, by explicitly returning occurances from traversing the original branch,
194194
-- and returning True, which keeps syb from implicitly continuing to traverse.
195-
getRecSels (unLoc -> XExpr (HsExpanded a _)) = (listToMaybe $ collectRecordSelectors a, True)
195+
getRecSels (unLoc -> XExpr (HsExpanded a _)) = (collectRecordSelectors a, True)
196196
#if __GLASGOW_HASKELL__ >= 903
197197
-- applied record selection: "field record" or "field (record)" or "field field.record"
198198
getRecSels e@(unLoc -> HsApp _ se@(unLoc -> HsRecSel _ _) re) =
199-
(listToMaybe [ RecordSelectorExpr (realSrcSpanToRange realSpan') se re | RealSrcSpan realSpan' _ <- [ getLoc e ]], False)
199+
( [ RecordSelectorExpr (realSrcSpanToRange realSpan') se re | RealSrcSpan realSpan' _ <- [ getLoc e ]], False)
200200
-- Record selection where the field is being applied with the "$" operator: "field $ record"
201201
getRecSels e@(unLoc -> OpApp _ se@(unLoc -> HsRecSel _ _) (unLoc -> HsVar _ (unLoc -> d)) re)
202-
| d == dollarName = (listToMaybe [ RecordSelectorExpr (realSrcSpanToRange realSpan') se re | RealSrcSpan realSpan' _ <- [ getLoc e ]], False)
202+
| d == dollarName = ( [ RecordSelectorExpr (realSrcSpanToRange realSpan') se re | RealSrcSpan realSpan' _ <- [ getLoc e ]], False)
203203
#else
204204
getRecSels e@(unLoc -> HsApp _ se@(unLoc -> HsRecFld _ _) re) =
205-
(listToMaybe [ RecordSelectorExpr (realSrcSpanToRange realSpan') se re | RealSrcSpan realSpan' _ <- [ getLoc e ]], False)
205+
( [ RecordSelectorExpr (realSrcSpanToRange realSpan') se re | RealSrcSpan realSpan' _ <- [ getLoc e ]], False)
206206
getRecSels e@(unLoc -> OpApp _ se@(unLoc -> HsRecFld _ _) (unLoc -> HsVar _ (unLoc -> d)) re)
207-
| d == dollarName = (listToMaybe [ RecordSelectorExpr (realSrcSpanToRange realSpan') se re | RealSrcSpan realSpan' _ <- [ getLoc e ]], False)
207+
| d == dollarName = ( [ RecordSelectorExpr (realSrcSpanToRange realSpan') se re | RealSrcSpan realSpan' _ <- [ getLoc e ]], False)
208208
#endif
209-
getRecSels _ = (Nothing, False)
209+
getRecSels _ = ([], False)
210210

211211
collectRecSelResult :: MonadIO m => IdeState -> NormalizedFilePath -> ExceptT String m CollectRecordSelectorsResult
212212
collectRecSelResult ideState =

0 commit comments

Comments
 (0)