Example #1
0
        private bool IsMultipleLines(TextSpan textSpan)
        {
            var start = _sourceText.GetLineFromPosition(textSpan.Start);
            var end   = _sourceText.GetLineFromPosition(textSpan.End);

            return(start.LineNumber != end.LineNumber);
        }
Example #2
0
        private TextSpan GetDiagnosticSpanForMissingToken()
        {
            if (_tokenIndex > 0)
            {
                var previousToken     = _tokens[_tokenIndex - 1];
                var previousTokenLine = _text.GetLineFromPosition(previousToken.Span.End);
                var currentTokenLine  = _text.GetLineFromPosition(Current.Span.Start);
                if (currentTokenLine != previousTokenLine)
                {
                    return(new TextSpan(previousToken.Span.End, 2));
                }
            }

            return(Current.Span);
        }
        public static int ToOffset(this SourceText text, int position)
        {
            var textLine = text.GetLineFromPosition(position);
            var line     = textLine.LineNumber;
            var delta    = Enumerable.Range(0, line).Select(i => text.Lines[i].LineBreakLength - 1).Sum();
            var offset   = position - delta;

            return(offset);
        }