diff --git a/src/Juvix/Data/Comment.hs b/src/Juvix/Data/Comment.hs index aee583fc52..62e1eb6aa2 100644 --- a/src/Juvix/Data/Comment.hs +++ b/src/Juvix/Data/Comment.hs @@ -6,7 +6,7 @@ import Juvix.Data.CodeAnn (CodeAnn (..), PrettyCodeAnn, ppCodeAnn) import Juvix.Data.Loc import Juvix.Extra.Strings qualified as Str import Juvix.Prelude.Base -import Prettyprinter +import Prettyprinter hiding (concatWith) newtype Comments = Comments { _commentsByFile :: HashMap (Path Abs File) FileComments @@ -117,12 +117,17 @@ instance Pretty Comment where . trimPrefixSpace trimPrefixSpace :: Text -> Text - trimPrefixSpace = - fromJust - . Text.stripSuffix "\n" - . Text.unlines - . map Text.strip - . Text.lines + trimPrefixSpace txt = case Text.unsnoc txt of + Nothing -> "" + Just (_, l) -> + appendNl + . concatWith (\a b -> a <> "\n" <> b) + . map Text.strip + . Text.lines + $ txt + where + lastnl = '\n' == l + appendNl = if lastnl then (<> "\n") else id allComments :: Comments -> [Comment] allComments c = diff --git a/tests/positive/Format.juvix b/tests/positive/Format.juvix index 85d245f4a1..f4a054a506 100644 --- a/tests/positive/Format.juvix +++ b/tests/positive/Format.juvix @@ -38,7 +38,7 @@ terminating go : Nat → Nat → Nat | n s := ite (s < n) (go (sub n 1) s) (go n (sub s n) + go (sub n 1) s); -module {- local module -} +module {-local module-} M; syntax -- syntax in local modules operator , pair; @@ -534,6 +534,18 @@ module MultiIf; | else := 2; end; +{-hi + +-} +module CommentAfterFun; + myfun (a : Nat) : Nat := + {- + My comment. + -} + {-othercomment-} + 1; +end; + module PublicImports; module Inner;