Skip to content

Commit 418958f

Browse files
authored
Limit diagnostics output and enhance logging clarity (#208)
1 parent 34910ca commit 418958f

File tree

7 files changed

+62
-16
lines changed

7 files changed

+62
-16
lines changed

src/Elastic.Markdown/DocumentationGenerator.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ await Parallel.ForEachAsync(DocumentationSet.Files, ctx, async (file, token) =>
8888
throw;
8989
}
9090

91-
if (processedFiles % 1_000 == 0)
92-
_logger.LogInformation($"Handled {processedFiles} files");
91+
if (processedFiles % 100 == 0)
92+
_logger.LogInformation($"-> Handled {processedFiles} files");
9393
});
9494

95+
_logger.LogInformation($"Copying static files to output directory");
9596
var embeddedStaticFiles = Assembly.GetExecutingAssembly()
9697
.GetManifestResourceNames()
9798
.ToList();
@@ -112,12 +113,19 @@ await Parallel.ForEachAsync(DocumentationSet.Files, ctx, async (file, token) =>
112113
}
113114

114115

116+
_logger.LogInformation($"Completing diagnostics channel");
115117
Context.Collector.Channel.TryComplete();
116118

119+
_logger.LogInformation($"Generating documentation compilation state");
117120
await GenerateDocumentationState(ctx);
121+
_logger.LogInformation($"Generating links.json");
118122
await GenerateLinkReference(ctx);
119123

124+
_logger.LogInformation($"Completing diagnostics channel");
125+
120126
await Context.Collector.StopAsync(ctx);
127+
128+
_logger.LogInformation($"Completed diagnostics channel");
121129
}
122130

123131
private async Task ProcessFile(HashSet<string> offendingFiles, DocumentationFile file, DateTimeOffset outputSeenChanges, CancellationToken token)

src/Elastic.Markdown/Helpers/Interpolation.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public static class Interpolation
1717
public static bool ReplaceSubstitutions(this ReadOnlySpan<char> span, Dictionary<string, string>? properties, out string? replacement)
1818
{
1919
replacement = null;
20+
if (span.IndexOf("}}") < 0)
21+
return false;
22+
2023
var substitutions = properties ?? new();
2124
if (substitutions.Count == 0)
2225
return false;

src/Elastic.Markdown/IO/Discovery/GitCheckoutInformation.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public string? RepositoryName
4040
public static GitCheckoutInformation Create(IFileSystem fileSystem)
4141
{
4242
// filesystem is not real so return a dummy
43+
var fakeRef = Guid.NewGuid().ToString().Substring(0, 16);
4344
if (fileSystem is not FileSystem)
4445
{
45-
var fakeRef = Guid.NewGuid().ToString().Substring(0, 16);
4646
return new GitCheckoutInformation
4747
{
4848
Branch = $"test-{fakeRef}",
@@ -56,14 +56,14 @@ public static GitCheckoutInformation Create(IFileSystem fileSystem)
5656
if (!gitConfig.Exists)
5757
return Unavailable;
5858

59-
var head = Read(".git/HEAD");
59+
var head = Read(".git/HEAD") ?? fakeRef;
6060
var gitRef = head;
6161
var branch = head.Replace("refs/heads/", string.Empty);
6262
//not detached HEAD
6363
if (head.StartsWith("ref:"))
6464
{
6565
head = head.Replace("ref: ", string.Empty);
66-
gitRef = Read(".git/" + head);
66+
gitRef = Read(".git/" + head) ?? fakeRef;
6767
branch = branch.Replace("ref: ", string.Empty);
6868
}
6969
else
@@ -94,8 +94,13 @@ public static GitCheckoutInformation Create(IFileSystem fileSystem)
9494

9595
IFileInfo Git(string path) => fileSystem.FileInfo.New(Path.Combine(Paths.Root.FullName, path));
9696

97-
string Read(string path) =>
98-
fileSystem.File.ReadAllText(Git(path).FullName).Trim(Environment.NewLine.ToCharArray());
97+
string? Read(string path)
98+
{
99+
var gitPath = Git(path).FullName;
100+
if (!fileSystem.File.Exists(gitPath))
101+
return null;
102+
return fileSystem.File.ReadAllText(gitPath).Trim(Environment.NewLine.ToCharArray());
103+
}
99104

100105
string BranchTrackingRemote(string b, IniFile c)
101106
{

src/Elastic.Markdown/Myst/CodeBlocks/CallOutParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public static partial class CallOutParser
1111
[GeneratedRegex(@"^.+\S+.*?\s<\d+>$", RegexOptions.IgnoreCase, "en-US")]
1212
public static partial Regex CallOutNumber();
1313

14-
[GeneratedRegex(@"^.+\S+.*?\s(?:\/\/|#)\s[^""]+$", RegexOptions.IgnoreCase, "en-US")]
14+
[GeneratedRegex(@"^.+\S+.*?\s(?:\/\/|#)\s[^""\/#]+$", RegexOptions.IgnoreCase, "en-US")]
1515
public static partial Regex MathInlineAnnotation();
1616
}

src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockParser.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,19 @@ public override bool Close(BlockProcessor processor, Block block)
9898
if (codeBlock.OpeningFencedCharCount > 3)
9999
continue;
100100

101-
var matchClassicCallout = CallOutParser.CallOutNumber().EnumerateMatches(span);
102-
var callOut = EnumerateAnnotations(matchClassicCallout, ref span, ref callOutIndex, originatingLine, false);
101+
if (span.IndexOf("<") < 0 && span.IndexOf("//") < 0)
102+
continue;
103103

104-
if (callOut is null)
104+
CallOut? callOut = null;
105+
106+
if (span.IndexOf("<") > 0)
107+
{
108+
var matchClassicCallout = CallOutParser.CallOutNumber().EnumerateMatches(span);
109+
callOut = EnumerateAnnotations(matchClassicCallout, ref span, ref callOutIndex, originatingLine, false);
110+
}
111+
112+
// only support magic callouts for smaller line lengths
113+
if (callOut is null && span.Length < 200)
105114
{
106115
var matchInline = CallOutParser.MathInlineAnnotation().EnumerateMatches(span);
107116
callOut = EnumerateAnnotations(matchInline, ref span, ref callOutIndex, originatingLine,

src/docs-builder/Diagnostics/Console/ConsoleDiagnosticsCollector.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,21 @@ public class ConsoleDiagnosticsCollector(ILoggerFactory loggerFactory, ICoreServ
1414
: DiagnosticsCollector([new Log(loggerFactory.CreateLogger<Log>()), new GithubAnnotationOutput(githubActions)]
1515
)
1616
{
17-
private readonly List<Diagnostic> _items = new();
17+
private readonly List<Diagnostic> _errors = new();
18+
private readonly List<Diagnostic> _warnings = new();
1819

19-
protected override void HandleItem(Diagnostic diagnostic) => _items.Add(diagnostic);
20+
protected override void HandleItem(Diagnostic diagnostic)
21+
{
22+
if (diagnostic.Severity == Severity.Warning)
23+
_warnings.Add(diagnostic);
24+
else
25+
_errors.Add(diagnostic);
26+
}
2027

2128
public override async Task StopAsync(Cancel ctx)
2229
{
2330
var repository = new ErrataFileSourceRepository();
24-
repository.WriteDiagnosticsToConsole(_items);
31+
repository.WriteDiagnosticsToConsole(_errors, _warnings);
2532

2633
AnsiConsole.WriteLine();
2734
AnsiConsole.Write(new Markup($" [bold red]{Errors} Errors[/] / [bold blue]{Warnings} Warnings[/]"));

src/docs-builder/Diagnostics/Console/ErrataFileSourceRepository.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ public bool TryGet(string id, [NotNullWhen(true)] out Source? source)
2222
return true;
2323
}
2424

25-
public void WriteDiagnosticsToConsole(IReadOnlyCollection<Diagnostic> items)
25+
public void WriteDiagnosticsToConsole(IReadOnlyCollection<Diagnostic> errors, IReadOnlyCollection<Diagnostic> warnings)
2626
{
2727
var report = new Report(this);
28-
foreach (var item in items)
28+
var limttedErrors = errors.Take(100).ToArray();
29+
var limittedWarnings = warnings.Take(100 - limttedErrors.Length);
30+
var limitted = limittedWarnings.Concat(limttedErrors).ToArray();
31+
32+
foreach (var item in limitted)
2933
{
3034
var d = item.Severity switch
3135
{
@@ -49,5 +53,15 @@ public void WriteDiagnosticsToConsole(IReadOnlyCollection<Diagnostic> items)
4953

5054
// Render the report
5155
report.Render(AnsiConsole.Console);
56+
57+
var totalErrorCount = errors.Count + warnings.Count;
58+
if (limitted.Length >= totalErrorCount)
59+
return;
60+
61+
AnsiConsole.WriteLine();
62+
AnsiConsole.WriteLine();
63+
AnsiConsole.Write(new Markup($"Displayed first [bold]{limitted.Length}[/] error/warnings out of [bold]{totalErrorCount}[/]"));
64+
65+
AnsiConsole.WriteLine();
5266
}
5367
}

0 commit comments

Comments
 (0)