Skip to content

Commit

Permalink
Fixes #151 Formatting comments adds empty lines in some situations
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Lischke <mike@lischke-online.de>
  • Loading branch information
mike-lischke committed Nov 11, 2023
1 parent 0f7fc6d commit 3cacf2e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/backend/Formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2110,6 +2110,7 @@ export class GrammarFormatter {
}

let index = 1;
let haveContent = false; // True if we have content beyond the introducer on the current line.
let column = this.computeLineLength(line);
while (true) {
while (index < pipeline.length) {
Expand All @@ -2119,6 +2120,8 @@ export class GrammarFormatter {
line = lineIntroducer;
column = this.computeLineLength(line);
}

haveContent = true;
line += pipeline[index++] + " ";
column = this.computeLineLength(line);
}
Expand Down Expand Up @@ -2155,17 +2158,18 @@ export class GrammarFormatter {

if (pipeline.length === 0) {
// Keep empty lines. Push the current line only if this is not still the first line
// (because we already pushed it already).
// (because then we pushed it already).
if (!isFirst) {
result.push(line.slice(0, -1));
}
result.push(lineIntroducer);
line = lineIntroducer;
haveContent = false;
}
isFirst = false;
}

if (line.length > 0) {
if (line.length > 0 && haveContent) {
result.push(line.slice(0, -1));
}

Expand Down

0 comments on commit 3cacf2e

Please sign in to comment.