From c522a455df3817d98c2cd9132668c4eb9fbb0d88 Mon Sep 17 00:00:00 2001 From: Miran Date: Tue, 2 Jul 2019 10:52:46 +0200 Subject: [PATCH] [bugfix] nimpretty indents multiline comments correctly (#11607) --- compiler/layouter.nim | 4 ++++ nimpretty/tests/exhaustive.nim | 19 +++++++++++++++++++ nimpretty/tests/expected/exhaustive.nim | 19 +++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/compiler/layouter.nim b/compiler/layouter.nim index 546d4766e4..e45e6400aa 100644 --- a/compiler/layouter.nim +++ b/compiler/layouter.nim @@ -145,6 +145,10 @@ proc closeEmitter*(em: var Emitter) = maxLhs = 0 lineBegin = i+1 of ltTab: + if i >= 2 and em.kinds[i-2] == ltNewline and em.kinds[i-1] in {ltNewline, ltSpaces}: + # a previous section has ended + maxLhs = 0 + if maxLhs == 0: content.add em.tokens[i] inc lineLen, em.tokens[i].len diff --git a/nimpretty/tests/exhaustive.nim b/nimpretty/tests/exhaustive.nim index ffdc95ccad..68d71e7a57 100644 --- a/nimpretty/tests/exhaustive.nim +++ b/nimpretty/tests/exhaustive.nim @@ -657,3 +657,22 @@ type key*, val*: TaintedString ## Key and value pair; the key is the option ## or the argument, and the value is not "" if ## the option was given a value + +block: + var t = 3 + +## This MUST be a multiline comment, +## single line comment would be ok. +block: + var x = 7 + + +block: + var t = 3 + ## another + ## multi + +## This MUST be a multiline comment, +## single line comment would be ok. +block: + var x = 7 diff --git a/nimpretty/tests/expected/exhaustive.nim b/nimpretty/tests/expected/exhaustive.nim index 4d0366afb2..4d1b933efd 100644 --- a/nimpretty/tests/expected/exhaustive.nim +++ b/nimpretty/tests/expected/exhaustive.nim @@ -663,3 +663,22 @@ type key*, val*: TaintedString ## Key and value pair; the key is the option ## or the argument, and the value is not "" if ## the option was given a value + +block: + var t = 3 + +## This MUST be a multiline comment, +## single line comment would be ok. +block: + var x = 7 + + +block: + var t = 3 + ## another + ## multi + +## This MUST be a multiline comment, +## single line comment would be ok. +block: + var x = 7