Skip to content

Commit df47a4c

Browse files
authored
fix spacing issues while refactor-reduce (#4841)
1 parent 8e0dbe2 commit df47a4c

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ dropHsParTy :: LHsType (GhcPass pass) -> LHsType (GhcPass pass)
141141
dropHsParTy (L _ (HsParTy _ ty)) = ty
142142
dropHsParTy other = other
143143

144+
normalizeConstraintDP :: [LocatedAn AnnListItem (HsType GhcPs)] -> [LocatedAn AnnListItem (HsType GhcPs)]
145+
normalizeConstraintDP [] = []
146+
normalizeConstraintDP xs = normalizeFirst xs
147+
where
148+
normalizeFirst (x:rest) = setEntryDP x (SameLine 0) : rest
149+
normalizeFirst [] = []
150+
144151
removeConstraint ::
145152
-- | Predicate: Which context to drop.
146153
(LHsType GhcPs -> Bool) ->
@@ -154,15 +161,13 @@ removeConstraint toRemove = go . traceAst "REMOVE_CONSTRAINT_input"
154161
#else
155162
go (L l it@HsQualTy{hst_ctxt = L l' ctxt, hst_body}) = Rewrite (locA l) $ \_ -> do
156163
#endif
157-
let ctxt' = filter (not . toRemove) ctxt
158-
removeStuff = (toRemove <$> headMaybe ctxt) == Just True
159-
let hst_body' = if removeStuff then resetEntryDP hst_body else hst_body
164+
let ctxt' = normalizeConstraintDP $ filter (not . toRemove) ctxt
160165
return $ case ctxt' of
161-
[] -> hst_body'
166+
[] -> hst_body
162167
_ -> do
163168
let ctxt'' = over _last (first removeComma) ctxt'
164169
L l $ it{ hst_ctxt = L l' ctxt''
165-
, hst_body = hst_body'
170+
, hst_body = hst_body
166171
}
167172
go (L _ (HsParTy _ ty)) = go ty
168173
go (L _ HsForAllTy{hst_body}) = go hst_body
@@ -244,11 +249,6 @@ liftParseAST df s = case parseAST df "" s of
244249
Right x -> pure (makeDeltaAst x)
245250
Left _ -> TransformT $ lift $ Left $ "No parse: " <> s
246251

247-
248-
headMaybe :: [a] -> Maybe a
249-
headMaybe [] = Nothing
250-
headMaybe (a : _) = Just a
251-
252252
lastMaybe :: [a] -> Maybe a
253253
lastMaybe [] = Nothing
254254
lastMaybe other = Just $ last other

plugins/hls-refactor-plugin/test/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3288,15 +3288,15 @@ removeRedundantConstraintsTests = let
32883288
]
32893289

32903290
typeSignatureLined3 = T.unlines $ header <>
3291-
[ "foo :: ( Eq a"
3291+
[ "foo :: (Eq a"
32923292
, " , Show a"
32933293
, " )"
32943294
, " => a -> Bool"
32953295
, "foo x = x == x"
32963296
]
32973297

32983298
typeSignatureLined3' = T.unlines $ header <>
3299-
[ "foo :: ( Eq a"
3299+
[ "foo :: (Eq a"
33003300
, " )"
33013301
, " => a -> Bool"
33023302
, "foo x = x == x"

0 commit comments

Comments
 (0)