private VirtualTreePoint GetBodyStartPoint(SourceText text, SyntaxToken openBrace, SyntaxToken closeBrace, int memberStartColumn) { Debug.Assert(!openBrace.IsMissing); Debug.Assert(!closeBrace.IsMissing); Debug.Assert(memberStartColumn >= 0); var openBraceLine = text.Lines.GetLineFromPosition(openBrace.SpanStart); var closeBraceLine = text.Lines.GetLineFromPosition(closeBrace.SpanStart); var tokenAfterOpenBrace = openBrace.GetNextToken(); var nextPosition = tokenAfterOpenBrace.SpanStart; // We need to check if there is any significant trivia trailing this token or leading // to the next token. This accounts for the fact that comments were included in the token // stream in Dev10. var significantTrivia = openBrace.GetAllTrailingTrivia() .Where(t => !t.MatchesKind(SyntaxKind.WhitespaceTrivia, SyntaxKind.EndOfLineTrivia)) .FirstOrDefault(); if (significantTrivia.Kind() != SyntaxKind.None) { nextPosition = significantTrivia.SpanStart; } // If the opening and closing curlies are at least two lines apart then place the cursor // on the next line provided that there isn't any token on the line with the open curly. if (openBraceLine.LineNumber + 1 < closeBraceLine.LineNumber && openBraceLine.LineNumber < text.Lines.IndexOf(tokenAfterOpenBrace.SpanStart)) { var lineAfterOpenBrace = text.Lines[openBraceLine.LineNumber + 1]; var firstNonWhitespaceOffset = lineAfterOpenBrace.GetFirstNonWhitespaceOffset() ?? -1; // If the line contains any text, we return the start of the first non-whitespace character. if (firstNonWhitespaceOffset >= 0) { return new VirtualTreePoint(openBrace.SyntaxTree, text, lineAfterOpenBrace.Start + firstNonWhitespaceOffset); } // If the line is all whitespace then place the caret at the first indent after the start // of the member. var indentSize = GetTabSize(text); var lineText = lineAfterOpenBrace.ToString(); var lineEndColumn = lineText.GetColumnFromLineOffset(lineText.Length, indentSize); int indentColumn = memberStartColumn + indentSize; var virtualSpaces = indentColumn - lineEndColumn; return new VirtualTreePoint(openBrace.SyntaxTree, text, lineAfterOpenBrace.End, virtualSpaces); } else { // If the body is empty then place it after the open brace; otherwise, place // at the start of the first token after the open curly. if (closeBrace.SpanStart == nextPosition) { return new VirtualTreePoint(openBrace.SyntaxTree, text, openBrace.Span.End); } else { return new VirtualTreePoint(openBrace.SyntaxTree, text, nextPosition); } } }