@@ -6,13 +6,17 @@ module Ormolu.Printer.Comments
66 ( spitPrecedingComments,
77 spitFollowingComments,
88 spitRemainingComments,
9+ spitStackHeader,
910 )
1011where
1112
1213import Control.Monad
14+import Data.Char (isSpace)
1315import Data.Coerce (coerce)
1416import Data.Data (Data)
17+import Data.List (isPrefixOf)
1518import qualified Data.List.NonEmpty as NE
19+import Data.List.NonEmpty (NonEmpty (..))
1620import qualified Data.Text as T
1721import Ormolu.Parser.CommentStream
1822import Ormolu.Printer.Internal
@@ -50,6 +54,16 @@ spitFollowingComments ref = do
5054spitRemainingComments :: R ()
5155spitRemainingComments = void $ handleCommentSeries spitRemainingComment
5256
57+-- | If there is a stack header in the comment stream, print it.
58+spitStackHeader :: R ()
59+spitStackHeader = do
60+ let isStackHeader (Comment (x :| _)) =
61+ "stack" `isPrefixOf` dropWhile isSpace (drop 2 x)
62+ mstackHeader <- popComment (isStackHeader . unRealSrcSpan)
63+ forM_ mstackHeader $ \(L spn x) -> do
64+ spitCommentNow spn x
65+ newline
66+
5367----------------------------------------------------------------------------
5468-- Single-comment functions
5569