public static bool GuessSemicolonInsertionOffset(IReadonlyTextDocument data, MonoDevelop.Core.Text.ISegment curLine, int caretOffset, out int outOffset)
        {
            int  lastNonWsOffset = caretOffset;
            char lastNonWsChar   = '\0';

            outOffset = caretOffset;

            int max = curLine.EndOffset;

            int end = caretOffset;

            while (end > 1 && char.IsWhiteSpace(data.GetCharAt(end)))
            {
                end--;
            }
            int end2 = end;

            while (end2 > 1 && char.IsLetter(data.GetCharAt(end2 - 1)))
            {
                end2--;
            }
            if (end != end2)
            {
                string token = data.GetTextBetween(end2, end + 1);
                // guess property context
                if (token == "get" || token == "set")
                {
                    return(false);
                }
            }

            var    offset   = curLine.Offset;
            string lineText = data.GetTextAt(caretOffset, max - caretOffset);
            var    lexer    = new ICSharpCode.NRefactory.CSharp.Completion.CSharpCompletionEngineBase.MiniLexer(lineText);

            lexer.Parse((ch, i) => {
                if (lexer.IsInSingleComment || lexer.IsInMultiLineComment)
                {
                    return(true);
                }
                if (ch == '}' && lexer.IsFistNonWs && !IsSemicolonalreadyPlaced(data, caretOffset))
                {
                    lastNonWsChar = ';';
                    return(true);
                }
                if (!char.IsWhiteSpace(ch))
                {
                    lastNonWsOffset = caretOffset + i;
                    lastNonWsChar   = ch;
                }
                return(false);
            });
            // if the line ends with ';' the line end is not the correct place for a new semicolon.
            if (lastNonWsChar == ';')
            {
                return(false);
            }
            outOffset = lastNonWsOffset;
            return(true);
        }
 public void AddStyle(MonoDevelop.Core.Text.ISegment segment, string style)
 {
     if (IsDirty)
     {
         return;
     }
     Add(new StyledTreeSegment(segment.Offset, segment.Length, style));
 }