Exemple #1
0
        private void InitPosition(SyntaxTree tree, TextSpan span)
        {
            var x = tree.GetLineSpan(span);
            this._line = x.StartLinePosition.Line + 1;
            this._column = x.StartLinePosition.Character + 1;

            this._endLine = x.EndLinePosition.Line + 1;
            this._endColumn = x.EndLinePosition.Character + 1;
        }
		protected override IEnumerable<string> ReportAllErrors(SyntaxTree userSolution)
		{
			var text = userSolution.GetText();
			var longLines = text.Lines.Where(line => line.End - line.Start > maxLineLen).ToList();
			if (longLines.Count == 0) yield break;
			var position = userSolution.GetLineSpan(longLines[0].Span);
			yield return Report(
				position, 
				"Слишком длинная строка. Не заставляйте людей использовать горизонтальный скролл");
		}
        public override FileLinePositionSpan GetLineSpan()
        {
            // If there's no syntax tree (e.g. because we're binding speculatively),
            // then just return an invalid span.
            if (_syntaxTree == null)
            {
                FileLinePositionSpan result = default(FileLinePositionSpan);
                Debug.Assert(!result.IsValid);
                return(result);
            }

            return(_syntaxTree.GetLineSpan(_span));
        }
        private static int GetIndentationSteps(IndentationSettings indentationSettings, SyntaxTree syntaxTree, SyntaxTriviaList leadingTrivia)
        {
            var triviaSpan = syntaxTree.GetLineSpan(leadingTrivia.FullSpan);

            // There is no indentation when the leading trivia doesn't begin at the start of the line.
            if ((triviaSpan.StartLinePosition == triviaSpan.EndLinePosition) && (triviaSpan.StartLinePosition.Character > 0))
            {
                return 0;
            }

            var builder = StringBuilderPool.Allocate();

            foreach (SyntaxTrivia trivia in leadingTrivia.Reverse())
            {
                if (!trivia.IsKind(SyntaxKind.WhitespaceTrivia))
                {
                    break;
                }

                builder.Insert(0, trivia.ToFullString());
            }

            var tabSize = indentationSettings.TabSize;
            var indentationCount = 0;
            for (var i = 0; i < builder.Length; i++)
            {
                indentationCount += builder[i] == '\t' ? tabSize - (indentationCount % tabSize) : 1;
            }

            StringBuilderPool.ReturnAndFree(builder);

            return (indentationCount + (indentationSettings.IndentationSize / 2)) / indentationSettings.IndentationSize;
        }
Exemple #5
0
 public CompleterError(SyntaxTree tree, Message message, SyntaxToken token)
     : this(tree, message, tree.GetLineSpan(token.Span))
 {
 }
 private int GetStartLinePosition(SyntaxTree syntaxTree, TextSpan textSpan)
 {
     return syntaxTree.GetLineSpan(textSpan).StartLinePosition.Line;
 }