Microsoft.R.Editor.Tree.TextChangeAnalyzer.CheckChangeInsideComment C# (CSharp) Method

CheckChangeInsideComment() private static method

private static CheckChangeInsideComment ( TextChangeContext context ) : TextChangeType
context TextChangeContext
return TextChangeType
        private static TextChangeType CheckChangeInsideComment(TextChangeContext context) {
            var comments = context.EditorTree.AstRoot.Comments;

            IReadOnlyList<int> affectedComments = comments.GetItemsContainingInclusiveEnd(context.NewStart);
            if (affectedComments.Count == 0) {
                return TextChangeType.Trivial;
            }

            if (affectedComments.Count > 1) {
                return TextChangeType.Structure;
            }

            // Make sure user is not deleting leading # effectively 
            // destroying the comment
            RToken comment = comments[affectedComments[0]];
            if (comment.Start == context.NewStart && context.OldLength > 0) {
                return TextChangeType.Structure;
            }

            // The collection will return a match if the comment starts 
            // at the requested location. However, the change is not 
            // inside the comment if it's at the comment start and 
            // the old length of the change is zero.

            if (comment.Start == context.NewStart && context.OldLength == 0) {
                if (context.NewText.IndexOf('#') < 0) {
                    context.ChangedComment = comment;
                    return TextChangeType.Comment;
                }
            }

            if (context.NewText.IndexOfAny(CharExtensions.LineBreakChars) >= 0) {
                return TextChangeType.Structure;
            }

            // The change is not safe if old or new text contains line breaks
            // as in R comments runs to the end of the line and deleting
            // line break at the end of the comment may bring code into 
            // the comment range and change the entire file structure.

            if (context.OldText.IndexOfAny(CharExtensions.LineBreakChars) >= 0) {
                return TextChangeType.Structure;
            }

            context.ChangedComment = comment;
            return TextChangeType.Comment;
        }