Skip to content

Commit

Permalink
Handle multiline comments better
Browse files Browse the repository at this point in the history
closes #580
  • Loading branch information
belav committed Feb 5, 2022
1 parent 1518657 commit a4f1b40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion Src/CSharpier/DocPrinter/DocPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,19 @@ private void ProcessNextCommand()
this.Output.Append(this.EndOfLine);
}

this.Output.Append(indent.Value).Append(leadingComment.Comment);
// TODO do trailing comments need to do the same thing?
var stringReader = new StringReader(leadingComment.Comment);
var line = stringReader.ReadLine();
while (line != null)
{
this.Output.Append(indent.Value).Append(line.Trim());
line = stringReader.ReadLine();
if (line != null)
{
this.Output.Append(this.EndOfLine);
}
}

this.CurrentWidth = indent.Length;
this.NewLineNextStringValue = false;
this.SkipNextNewLine = false;
Expand Down
4 changes: 2 additions & 2 deletions Src/CSharpier/DocTypes/LeadingComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace CSharpier.DocTypes;

internal class LeadingComment : Doc
{
public CommentType Type { get; set; }
public string Comment { get; set; } = string.Empty;
public CommentType Type { get; init; }
public string Comment { get; init; } = string.Empty;
}

0 comments on commit a4f1b40

Please sign in to comment.