Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,36 +149,6 @@ public static int GetTokenColumn(this SyntaxTree tree, SyntaxToken token, int ta
return line.GetColumnFromLineOffset(startPosition - line.Start, tabSize);
}

public static bool IsFirstTokenOnLine(this SyntaxTree tree, SyntaxToken token)
{
Contract.ThrowIfNull(tree);
Contract.ThrowIfTrue(token.RawKind == 0);

var previousToken = token.GetPreviousToken();

// there should be only whitespace between two tokens unless the token can't be the first token on line
if (!string.IsNullOrWhiteSpace(tree.GetText().GetText(previousToken, token)))
{
return false;
}

if (previousToken.RawKind == 0)
{
return true;
}

var previousLine = tree.GetText().Lines.GetLineFromPosition(previousToken.Span.End);
var lineNumber = tree.GetText().Lines.IndexOf(token.SpanStart);

// if span.End is at the edge of two lines, it belongs to previous line
if (previousLine.Start == previousToken.Span.End)
{
return previousLine.LineNumber - 1 < lineNumber;
}

return previousLine.LineNumber < lineNumber;
}

public static string GetText(this SourceText text, SyntaxToken token1, SyntaxToken token2)
{
return (token1.RawKind == 0) ? text.ToString(TextSpan.FromBounds(0, token2.SpanStart)) : text.ToString(TextSpan.FromBounds(token1.Span.End, token2.SpanStart));
Expand Down