public void WriteDiagnosticsToConsole()

in src/tooling/Elastic.Documentation.Tooling/Diagnostics/Console/ErrataFileSourceRepository.cs [27:82]


	public void WriteDiagnosticsToConsole(IReadOnlyCollection<Diagnostic> errors, IReadOnlyCollection<Diagnostic> warnings, List<Diagnostic> hints)
	{
		var report = new Report(this);
		var limited = errors
			.Concat(warnings)
			.OrderBy(d => d.Severity switch { Severity.Error => 0, Severity.Warning => 1, Severity.Hint => 2, _ => 3 })
			.Take(100)
			.ToArray();

		// show hints if we don't have plenty of errors/warnings to show
		if (limited.Length < 100)
			limited = limited.Concat(hints).Take(100).ToArray();

		foreach (var item in limited)
		{
			var d = item.Severity switch
			{
				Severity.Error => Errata.Diagnostic.Error(item.Message),
				Severity.Warning => Errata.Diagnostic.Warning(item.Message),
				Severity.Hint => Errata.Diagnostic.Info(item.Message),
				_ => Errata.Diagnostic.Info(item.Message)
			};
			if (item is { Line: not null, Column: not null })
			{
				var location = new Location(item.Line ?? 0, item.Column ?? 0);
				d = d.WithLabel(new Label(item.File, location, "")
					.WithLength(item.Length == null ? 1 : Math.Clamp(item.Length.Value, 1, item.Length.Value + 3))
					.WithPriority(1)
					.WithColor(item.Severity switch
					{
						Severity.Error => Color.Red,
						Severity.Warning => Color.Blue,
						Severity.Hint => Color.Yellow,
						_ => Color.Blue
					}));
			}
			else
				d = d.WithNote(item.File);

			if (item.Severity == Severity.Hint)
				d = d.WithColor(Color.Yellow).WithCategory("Hint");

			_ = report.AddDiagnostic(d);
		}

		var totalErrorCount = errors.Count + warnings.Count;

		AnsiConsole.WriteLine();
		if (totalErrorCount <= 0)
		{
			if (hints.Count > 0)
				DisplayHintsOnly(report, hints);
			return;
		}
		DisplayErrorAndWarningSummary(report, totalErrorCount, limited);
	}