@@ -28,7 +28,7 @@ import qualified Lexer as GHC
2828import Ormolu.Parser.Pragma
2929import Ormolu.Parser.Shebang
3030import Ormolu.Processing.Common
31−import Ormolu.Utils (showOutputable)
31+import Ormolu.Utils (onTheSameLine, showOutputable)
3232import SrcLoc
3333
3434----------------------------------------------------------------------------
@@ -150,6 +150,7 @@ isMultilineComment (Comment _ (x :| _)) = "{-" `L.isPrefixOf` x
150150
151151-- | Detect and extract stack header if it is present.
152152extractStackHeader ::
153+ -- | Comment stream to analyze
153154 [RealLocated String] ->
154155 ([RealLocated String], Maybe (RealLocated Comment))
155156extractStackHeader = \case
@@ -165,7 +166,9 @@ extractStackHeader = \case
165166
166167-- | Extract pragmas and their associated comments.
167168extractPragmas ::
169+ -- | Input
168170 String ->
171+ -- | Comment stream to analyze
169172 [RealLocated String] ->
170173 ([RealLocated Comment], [([RealLocated Comment], Pragma)])
171174extractPragmas input = go initialLs id id
@@ -179,8 +182,17 @@ extractPragmas input = go initialLs id id
179182 let (ls', x') = mkComment ls x
180183 in go ls' (csSoFar . (x' :)) pragmasSoFar xs
181184 Just pragma ->
182− let combined = (csSoFar [], pragma)
183− in go ls id (pragmasSoFar . (combined :)) xs
185+ let combined ys = (csSoFar ys, pragma)
186+ go' ls' ys rest = go ls' id (pragmasSoFar . (combined ys :)) rest
187+ in case xs of
188+ [] -> go' ls [] xs
189+ (y : ys) ->
190+ let (ls', y') = mkComment ls y
191+ in if onTheSameLine
192+ (RealSrcSpan (getRealSrcSpan x))
193+ (RealSrcSpan (getRealSrcSpan y))
194+ then go' ls' [y'] ys
195+ else go' ls [] xs
184196
185197-- | Get a 'String' from 'GHC.AnnotationComment'.
186198unAnnotationComment :: GHC.AnnotationComment -> Maybe String