Skip to content

Commit

Permalink
Use an int instead of a stack
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwengier committed Oct 25, 2021
1 parent d1a7bae commit 230be75
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -23,8 +23,8 @@ internal class FormattingVisitor : SyntaxWalker
private SyntaxNode? _currentBlock;
private int _currentHtmlIndentationLevel = 0;
private int _currentRazorIndentationLevel = 0;
private int _currentComponentIndentationLevel = 0;
private bool _isInClassBody = false;
private readonly Stack<MarkupTagHelperElementSyntax> _componentTracker;

public FormattingVisitor(RazorSourceDocument source)
{
@@ -35,7 +35,6 @@ public FormattingVisitor(RazorSourceDocument source)

_source = source;
_spans = new List<FormattingSpan>();
_componentTracker = new Stack<MarkupTagHelperElementSyntax>();
_currentBlockKind = FormattingBlockKind.Markup;
}

@@ -205,7 +204,7 @@ public override void VisitMarkupTagHelperElement(MarkupTagHelperElementSyntax no
_currentHtmlIndentationLevel++;
if (causesIndentation)
{
_componentTracker.Push(node);
_currentComponentIndentationLevel++;
}

foreach (var child in node.Body)
@@ -215,8 +214,8 @@ public override void VisitMarkupTagHelperElement(MarkupTagHelperElementSyntax no

if (causesIndentation)
{
Debug.Assert(_componentTracker.Any(), "Component tracker should not be empty.");
_componentTracker.Pop();
Debug.Assert(_currentComponentIndentationLevel > 0, "Component tracker should not be empty.");
_currentComponentIndentationLevel--;
}
_currentHtmlIndentationLevel--;

@@ -442,8 +441,6 @@ private void WriteSpan(SyntaxNode node, FormattingSpanKind kind)
var spanSource = new TextSpan(node.Position, node.FullWidth);
var blockSource = new TextSpan(_currentBlock.Position, _currentBlock.FullWidth);

var componentLambdaNestingLevel = _componentTracker.Count;

var span = new FormattingSpan(
spanSource,
blockSource,
@@ -452,7 +449,7 @@ private void WriteSpan(SyntaxNode node, FormattingSpanKind kind)
_currentRazorIndentationLevel,
_currentHtmlIndentationLevel,
_isInClassBody,
componentLambdaNestingLevel);
_currentComponentIndentationLevel);

_spans.Add(span);
}

0 comments on commit 230be75

Please sign in to comment.