Skip to content

Commit b20093a

Browse files
authored
Merge branch 'main' into feature/collect-redirects
2 parents e889c86 + 66c0052 commit b20093a

File tree

23 files changed

+161
-100
lines changed

23 files changed

+161
-100
lines changed

docs/configure/content-set/navigation.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,25 @@ external_hosts:
5959
- github.com
6060
```
6161

62+
### `cross_links`
63+
64+
Defines repositories that contain documentation sets you want to link to. The purpose of this feature is to avoid using absolute links that require time-consuming crawling and checking.
65+
66+
Consider a docset repository called `bazinga`. The following example adds three docset repositories to its `docset.yml` file:
67+
68+
```yaml
69+
cross_links:
70+
- apm-server
71+
- cloud
72+
- docs-content
73+
```
74+
75+
To link to a document in the `docs-content` repository, you would write the link as follows:
76+
77+
```
78+
[Link to docs-content doc](docs-content://directory/another-directory/file.md)
79+
```
80+
6281
### `exclude`
6382

6483
Files to exclude from the TOC. Supports glob patterns.

src/Elastic.Documentation.Configuration/YamlStreamReader.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public record YamlToplevelKey
1616
public required KeyValuePair<YamlNode, YamlNode> Entry { get; init; }
1717
}
1818

19-
public class YamlStreamReader(IFileInfo source, DiagnosticsCollector collector)
19+
public class YamlStreamReader(IFileInfo source, IDiagnosticsCollector collector)
2020
{
2121
private IFileInfo Source { get; init; } = source;
22-
private DiagnosticsCollector Collector { get; init; } = collector;
22+
private IDiagnosticsCollector Collector { get; init; } = collector;
2323

2424
public IEnumerable<YamlToplevelKey> Read()
2525
{
@@ -185,7 +185,7 @@ private void EmitError(string message, Mark? start = null, Mark? end = null, int
185185
Column = start.HasValue ? (int)start.Value.Column : null,
186186
Length = length
187187
};
188-
Collector.Channel.Write(d);
188+
Collector.Write(d);
189189
}
190190
public void EmitWarning(string message, Mark? start = null, Mark? end = null, int? length = null)
191191
{
@@ -199,6 +199,6 @@ public void EmitWarning(string message, Mark? start = null, Mark? end = null, in
199199
Column = start.HasValue ? (int)start.Value.Column : null,
200200
Length = length
201201
};
202-
Collector.Channel.Write(d);
202+
Collector.Write(d);
203203
}
204204
}

src/Elastic.Documentation/Diagnostics/DiagnosticsCollector.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
namespace Elastic.Documentation.Diagnostics;
1010

11-
public class DiagnosticsCollector(IReadOnlyCollection<IDiagnosticsOutput> outputs) : IHostedService, IAsyncDisposable
11+
public class DiagnosticsCollector(IReadOnlyCollection<IDiagnosticsOutput> outputs)
12+
: IDiagnosticsCollector, IHostedService
1213
{
13-
public DiagnosticsChannel Channel { get; } = new();
14+
private DiagnosticsChannel Channel { get; } = new();
1415

1516
private int _errors;
1617
private int _warnings;
@@ -29,7 +30,13 @@ public class DiagnosticsCollector(IReadOnlyCollection<IDiagnosticsOutput> output
2930

3031
public bool NoHints { get; init; }
3132

32-
public Task StartAsync(Cancel cancellationToken)
33+
public DiagnosticsCollector StartAsync(Cancel ctx)
34+
{
35+
_ = ((IHostedService)this).StartAsync(ctx);
36+
return this;
37+
}
38+
39+
Task IHostedService.StartAsync(Cancel cancellationToken)
3340
{
3441
if (_started is not null)
3542
return _started;
@@ -59,7 +66,6 @@ void Drain()
5966
{
6067
if (item.Severity == Severity.Hint && NoHints)
6168
continue;
62-
IncrementSeverityCount(item);
6369
HandleItem(item);
6470
_ = OffendingFiles.Add(item.File);
6571
foreach (var output in outputs)
@@ -82,15 +88,22 @@ protected virtual void HandleItem(Diagnostic diagnostic) { }
8288

8389
public virtual async Task StopAsync(Cancel cancellationToken)
8490
{
91+
Channel.TryComplete();
8592
if (_started is not null)
8693
await _started;
8794
await Channel.Reader.Completion;
8895
}
8996

9097
public void EmitCrossLink(string link) => CrossLinks.Add(link);
9198

99+
public void Write(Diagnostic diagnostic)
100+
{
101+
IncrementSeverityCount(diagnostic);
102+
Channel.Write(diagnostic);
103+
}
104+
92105
private void Emit(Severity severity, string file, string message) =>
93-
Channel.Write(new Diagnostic
106+
Write(new Diagnostic
94107
{
95108
Severity = severity,
96109
File = file,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.Collections.Concurrent;
6+
using System.IO.Abstractions;
7+
8+
namespace Elastic.Documentation.Diagnostics;
9+
10+
public interface IDiagnosticsCollector : IAsyncDisposable
11+
{
12+
int Warnings { get; }
13+
int Errors { get; }
14+
int Hints { get; }
15+
16+
ConcurrentBag<string> CrossLinks { get; }
17+
HashSet<string> OffendingFiles { get; }
18+
ConcurrentDictionary<string, bool> InUseSubstitutionKeys { get; }
19+
20+
void EmitError(string file, string message, Exception? e = null);
21+
void EmitWarning(string file, string message);
22+
void EmitHint(string file, string message);
23+
void Write(Diagnostic diagnostic);
24+
void CollectUsedSubstitutionKey(ReadOnlySpan<char> key);
25+
void EmitCrossLink(string link);
26+
}
27+
28+
public static class DiagnosticsCollectorExtensions
29+
{
30+
public static void EmitError(this IDiagnosticsCollector collector, IFileInfo file, string message, Exception? e = null) =>
31+
collector.EmitError(file.FullName, message, e);
32+
33+
public static void EmitWarning(this IDiagnosticsCollector collector, IFileInfo file, string message) =>
34+
collector.EmitWarning(file.FullName, message);
35+
36+
public static void EmitHint(this IDiagnosticsCollector collector, IFileInfo file, string message) =>
37+
collector.EmitHint(file.FullName, message);
38+
}
39+
40+

src/Elastic.Documentation/IDocumentationContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Elastic.Documentation;
99

1010
public interface IDocumentationContext
1111
{
12-
DiagnosticsCollector Collector { get; }
12+
IDiagnosticsCollector Collector { get; }
1313
IDirectoryInfo DocumentationSourceDirectory { get; }
1414
GitCheckoutInformation Git { get; }
1515
IFileSystem ReadFileSystem { get; }

src/Elastic.Markdown/BuildContext.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public record BuildContext : IDocumentationContext
2626

2727
public GitCheckoutInformation Git { get; }
2828

29-
public DiagnosticsCollector Collector { get; }
29+
public IDiagnosticsCollector Collector { get; }
3030

3131
public bool Force { get; init; }
3232

@@ -47,14 +47,11 @@ public string? UrlPathPrefix
4747
init => _urlPathPrefix = value;
4848
}
4949

50-
public BuildContext(IFileSystem fileSystem)
51-
: this(new DiagnosticsCollector([]), fileSystem, fileSystem, null, null) { }
52-
53-
public BuildContext(DiagnosticsCollector collector, IFileSystem fileSystem)
50+
public BuildContext(IDiagnosticsCollector collector, IFileSystem fileSystem)
5451
: this(collector, fileSystem, fileSystem, null, null) { }
5552

5653
public BuildContext(
57-
DiagnosticsCollector collector,
54+
IDiagnosticsCollector collector,
5855
IFileSystem readFileSystem,
5956
IFileSystem writeFileSystem,
6057
string? source = null,

src/Elastic.Markdown/Diagnostics/ProcessorDiagnosticExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static void EmitError(this InlineProcessor processor, int line, int colum
3030
Message = message,
3131
Length = length
3232
};
33-
context.Build.Collector.Channel.Write(d);
33+
context.Build.Collector.Write(d);
3434
}
3535

3636

@@ -48,7 +48,7 @@ public static void EmitWarning(this InlineProcessor processor, int line, int col
4848
Message = message,
4949
Length = length
5050
};
51-
context.Build.Collector.Channel.Write(d);
51+
context.Build.Collector.Write(d);
5252
}
5353

5454
public static void EmitError(this ParserContext context, string message, Exception? e = null)
@@ -61,7 +61,7 @@ public static void EmitError(this ParserContext context, string message, Excepti
6161
File = context.MarkdownSourcePath.FullName,
6262
Message = CreateExceptionMessage(message, e),
6363
};
64-
context.Build.Collector.Channel.Write(d);
64+
context.Build.Collector.Write(d);
6565
}
6666

6767
public static void EmitWarning(this ParserContext context, int line, int column, int length, string message)
@@ -77,7 +77,7 @@ public static void EmitWarning(this ParserContext context, int line, int column,
7777
Message = message,
7878
Length = length
7979
};
80-
context.Build.Collector.Channel.Write(d);
80+
context.Build.Collector.Write(d);
8181
}
8282

8383
public static void EmitError(this IBlockExtension block, string message, Exception? e = null) => EmitDiagnostic(block, Severity.Error, message, e);
@@ -100,7 +100,7 @@ private static void EmitDiagnostic(IBlockExtension block, Severity severity, str
100100
Length = block.OpeningLength + 5,
101101
Message = CreateExceptionMessage(message, e),
102102
};
103-
block.Build.Collector.Channel.Write(d);
103+
block.Build.Collector.Write(d);
104104
}
105105

106106

@@ -121,7 +121,7 @@ private static void LinkDiagnostic(InlineProcessor processor, Severity severity,
121121
Message = CreateExceptionMessage(message, e),
122122
Length = Math.Max(length, 1)
123123
};
124-
context.Build.Collector.Channel.Write(d);
124+
context.Build.Collector.Write(d);
125125
}
126126

127127
public static void EmitError(this InlineProcessor processor, LinkInline inline, string message) =>

src/Elastic.Markdown/DocumentationGenerator.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,11 @@ public async Task<GenerationResult> GenerateAll(Cancel ctx)
138138
};
139139
}
140140

141-
public async Task StopDiagnosticCollection(Cancel ctx)
142-
{
143-
_logger.LogInformation($"Completing diagnostics channel");
144-
Context.Collector.Channel.TryComplete();
145-
146-
_logger.LogInformation($"Stopping diagnostics collector");
147-
await Context.Collector.StopAsync(ctx);
148-
149-
_logger.LogInformation($"Completed diagnostics channel");
150-
}
151-
152141
private async Task ProcessDocumentationFiles(HashSet<string> offendingFiles, DateTimeOffset outputSeenChanges, Cancel ctx)
153142
{
154143
var processedFileCount = 0;
155144
var exceptionCount = 0;
156145
var totalFileCount = DocumentationSet.Files.Count;
157-
_ = Context.Collector.StartAsync(ctx);
158146
await Parallel.ForEachAsync(DocumentationSet.Files, ctx, async (file, token) =>
159147
{
160148
var processedFiles = Interlocked.Increment(ref processedFileCount);

src/Elastic.Markdown/Helpers/Interpolation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ParserContext context
3131
public static bool ReplaceSubstitutions(
3232
this ReadOnlySpan<char> span,
3333
IReadOnlyDictionary<string, string>? properties,
34-
DiagnosticsCollector? collector,
34+
IDiagnosticsCollector? collector,
3535
[NotNullWhen(true)] out string? replacement
3636
)
3737
{
@@ -43,7 +43,7 @@ public static bool ReplaceSubstitutions(
4343
private static bool ReplaceSubstitutions(
4444
this ReadOnlySpan<char> span,
4545
IReadOnlyDictionary<string, string>[] properties,
46-
DiagnosticsCollector? collector,
46+
IDiagnosticsCollector? collector,
4747
[NotNullWhen(true)] out string? replacement
4848
)
4949
{

src/Elastic.Markdown/IO/MarkdownFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ DocumentationSet set
6666

6767
public string Id { get; } = Guid.NewGuid().ToString("N")[..8];
6868

69-
private DiagnosticsCollector Collector { get; }
69+
private IDiagnosticsCollector Collector { get; }
7070

7171
public bool Hidden { get; internal set; }
7272
public string? UrlPathPrefix { get; }

0 commit comments

Comments
 (0)