Skip to content

Commit

Permalink
Fixing bug with range ignore + regions
Browse files Browse the repository at this point in the history
closes #1197
  • Loading branch information
belav committed Mar 24, 2024
1 parent 88f8193 commit 668e166
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,12 @@ public class ClassName
#endregion one
;
}

class ClassName
{
#region Region
// csharpier-ignore-start
public string Field;
// csharpier-ignore-end
#endregion
}
15 changes: 12 additions & 3 deletions Src/CSharpier/DocPrinter/DocPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class DocPrinter
protected readonly string EndOfLine;
protected readonly PrinterOptions PrinterOptions;
protected readonly Indenter Indenter;
protected Stack<Indent> RegionIndents = new();
protected readonly Stack<Indent> RegionIndents = new();

protected DocPrinter(Doc doc, PrinterOptions printerOptions, string endOfLine)
{
Expand Down Expand Up @@ -156,8 +156,17 @@ private void ProcessNextCommand()
{
if (region.IsEnd)
{
var regionIndent = this.RegionIndents.Pop();
this.Output.Append(regionIndent.Value);
// in the case where regions are combined with ignored ranges, the start region
// ends up printing inside the unformatted nodes, so we don't have a matching
// start region to go with this end region
if (this.RegionIndents.TryPop(out var regionIndent))

Check failure on line 162 in Src/CSharpier/DocPrinter/DocPrinter.cs

View workflow job for this annotation

GitHub Actions / Run Tests

'Stack<Indent>' does not contain a definition for 'TryPop' and no accessible extension method 'TryPop' accepting a first argument of type 'Stack<Indent>' could be found (are you missing a using directive or an assembly reference?)
{
this.Output.Append(regionIndent.Value);
}
else
{
this.Output.Append(indent.Value);
}
}
else
{
Expand Down

0 comments on commit 668e166

Please sign in to comment.