Esempio n. 1
0
        public void printOn(TextWriter stream)
        {
            stream.WriteLine("");
            stream.Write(Environment.QualifiedName);
            stream.Write(": ");
            switch (Severity)
            {
            case Severity.Ignore:
                stream.Write("Note: [");
                break;

            case Severity.Warning:
                stream.Write("Warning: [");
                break;

            case Severity.Error:
                stream.Write("Error: [");
                break;

            case Severity.FatalError:
                stream.Write("Fatal error: [");
                break;
            }
            stream.Write(ErrorSpan.ToString());
            stream.Write("] ");
            stream.Write(ErrorDescription);
            if (errorCode > 0)
            {
                stream.Write(" (error code = " + ErrorCode);
                stream.Write(")");
            }
            stream.WriteLine();
        }
Esempio n. 2
0
    private static string FormatErrors(string message, ErrorSpan span, ReadOnlyMemory <char> resource, string?newLine)
    {
        var sb             = new StringBuilder();
        var errContext     = resource.Slice(span.StartSpan, span.EndSpan - span.StartSpan).ToString();
        var lines          = new List <ReadOnlyMemory <char> >(5);
        var currLineOffset = 0;
        var lastStart      = 0;

        for (var i = 0; i < span.StartMark - span.StartSpan; i++)
        {
            switch (errContext[i])
            {
            // Reset current line so that mark aligns with the reported error
            // We cheat here a bit, since we both `\r\n` and `\n` end with '\n'
            case '\n':
                if (i > 0 && errContext[i - 1] == '\r')
                {
                    lines.Add(resource.Slice(lastStart, currLineOffset - 1));
                }
                else
                {
                    lines.Add(resource.Slice(lastStart, currLineOffset));
                }

                lastStart      = currLineOffset + 1;
                currLineOffset = 0;
                break;

            default:
                currLineOffset++;
                break;
            }
        }

        lines.Add(resource.Slice(lastStart, resource.Length - lastStart));


        var lastLine = $"{span.Row + lines.Count - 1}".Length;

        for (var index = 0; index < lines.Count; index++)
        {
            var line = lines[index];

            sb.Append(newLine ?? Environment.NewLine).Append(' ').Append($"{span.Row + index}".PadLeft(lastLine))
            .Append(" |").Append(line);
        }

        sb.Append(newLine ?? Environment.NewLine)
        .Append(' ', currLineOffset + lastLine + 3)
        .Append('^', span.EndMark - span.StartMark)
        .Append($" {message}");
        return(sb.ToString());
    }
Esempio n. 3
0
        private static string FormatErrors(string message, ErrorSpan span, ReadOnlyMemory <char> resource)
        {
            var sb         = new StringBuilder();
            var row        = $"  {span.Row}  ";
            var errContext = resource.Slice(span.StartSpan, span.EndSpan - span.StartSpan).ToString();

            sb.Append(row).Append('|')
            .AppendLine(errContext);
            sb.Append(' ', row.Length).Append('|')
            .Append(' ', span.StartMark - span.StartSpan - 1).Append('^', span.EndMark - span.StartMark)
            .AppendLine($" {message}");
            return(sb.ToString());
        }