Skip to content

Commit

Permalink
Handling everything except for tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
belav committed Oct 28, 2023
1 parent b53d449 commit f6e7f80
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ var someOneWantsThisMuchIndentation = """
</element>
""";

var whatAboutWhiteSpace = """
Four Spaces

That last line is only two
""";

var whatAboutWhiteSpace = """
Four Spaces

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var someString = """
Indent based on previous line
""";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var someString = """
Indent based on previous line
""";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var whatAboutWhiteSpace = """
Four Spaces

That last line is only two
""";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var whatAboutWhiteSpace = """
Four Spaces

That last line is only two
""";
6 changes: 5 additions & 1 deletion Src/CSharpier/DocPrinter/DocPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@ private void ProcessLine(LineDoc line, PrintMode mode, Indent indent)
{
if (!this.SkipNextNewLine || !this.NewLineNextStringValue)
{
this.Output.TrimTrailingWhitespace();
if (line is not HardLineNoTrim)
{
this.Output.TrimTrailingWhitespace();
}

this.Output.Append(this.EndOfLine).Append(indent.Value);
this.CurrentWidth = indent.Length;
}
Expand Down
2 changes: 2 additions & 0 deletions Src/CSharpier/DocTypes/Doc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public static implicit operator Doc(string value)

public static readonly HardLine HardLine = new();

public static readonly HardLineNoTrim HardLineNoTrim = new();

public static readonly HardLine HardLineSkipBreakIfFirstInGroup = new(false, true);

public static readonly HardLine HardLineIfNoPreviousLine = new(true);
Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier/DocTypes/HardLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public HardLine(bool squash = false, bool skipBreakIfFirstInGroup = false)
this.Squash = squash;
this.SkipBreakIfFirstInGroup = skipBreakIfFirstInGroup;
}
}
}
3 changes: 3 additions & 0 deletions Src/CSharpier/DocTypes/HardLineNoTrim.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace CSharpier.DocTypes;

internal class HardLineNoTrim : HardLine { }
4 changes: 3 additions & 1 deletion Src/CSharpier/SyntaxPrinter/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ is InterpolatedStringExpressionSyntax
: string.Empty;
modifiedLine += line.TrimStart();
contents.Add(modifiedLine);
contents.Add(Doc.HardLine);
contents.Add(
numberOfSpacesToAddOrRemove > 0 ? Doc.HardLineNoTrim : Doc.HardLine
);
}

contents.RemoveAt(contents.Count - 1);
Expand Down

0 comments on commit f6e7f80

Please sign in to comment.