Exemplo n.º 1
0
        static void PrintDiagnostics(DiagnosticBag diagnostics, SourceText text)
        {
            foreach (Diagnostic diagnostic in diagnostics)
            {
                int      lineIndex = text.GetLineIndexByPosition(diagnostic.Span.Start);
                TextLine line      = text.Lines[lineIndex];

                int lineNumber      = lineIndex + 1;
                int characterNumber = diagnostic.Span.Start - line.Start + 1;

                Console.WriteLine();

                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.Write($"({lineNumber}, {characterNumber}): ");
                Console.WriteLine(diagnostic);
                Console.ResetColor();

                string prefix = text.ToString(line.Start, diagnostic.Span.Start - line.Start);
                string span   = text.ToString(diagnostic.Span.Start, diagnostic.Span.Length);
                string suffix = text.ToString(diagnostic.Span.End, line.End - diagnostic.Span.End);

                Console.Write("     ");
                Console.Write(prefix);

                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.Write(span);
                Console.ResetColor();

                Console.Write(suffix);

                Console.WriteLine();
            }
        }