Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ resharper_explicit_caller_info_argument_highlighting=hint

dotnet_diagnostic.IDE0057.severity = none

[DocumentationWebHost.cs]
dotnet_diagnostic.IL3050.severity = none
dotnet_diagnostic.IL2026.severity = none


[*.{sh,bat,ps1}]
trim_trailing_whitespace=true
insert_final_newline=true
Expand Down
2 changes: 1 addition & 1 deletion build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dotnet publish {generatorSource}
app.Add("notices", async Task<int> (Cancel ctx) =>
{
var packages = await "dotnet thirdlicense --project src/docs-builder/docs-builder.csproj --output NOTICE.txt";
var packageLines = packages.Split(Environment.NewLine).Where(l=>l.StartsWith("+"));
var packageLines = packages.Split(Environment.NewLine).Where(l => l.StartsWith("+"));

await File.WriteAllTextAsync("NOTICE.txt",
$"""
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Markdown/BuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public BuildContext(IFileSystem readFileSystem, IFileSystem writeFileSystem, str
: WriteFileSystem.DirectoryInfo.New(Path.Combine(Paths.Root.FullName, ".artifacts/docs/html"));

ConfigurationPath =
ReadFileSystem.FileInfo.New(Path.Combine(SourcePath.FullName, "docset.yml"));
ReadFileSystem.FileInfo.New(Path.Combine(SourcePath.FullName, "docset.yml"));

if (ConfigurationPath.FullName != SourcePath.FullName)
SourcePath = ConfigurationPath.Directory!;
Expand All @@ -63,7 +63,7 @@ public BuildContext(IFileSystem readFileSystem, IFileSystem writeFileSystem, str
private IDirectoryInfo FindDocsFolderFromRoot(IDirectoryInfo rootPath)
{
if (rootPath.Exists &&
ReadFileSystem.File.Exists(Path.Combine(rootPath.FullName, "docset.yml")))
ReadFileSystem.File.Exists(Path.Combine(rootPath.FullName, "docset.yml")))
return rootPath;

var docsFolder = rootPath.EnumerateFiles("docset.yml", SearchOption.AllDirectories).FirstOrDefault();
Expand Down
5 changes: 3 additions & 2 deletions src/Elastic.Markdown/Diagnostics/DiagnosticsChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class DiagnosticsCollector(ILoggerFactory loggerFactory, IReadOnlyCollect
: IHostedService
{
private readonly IReadOnlyCollection<IDiagnosticsOutput> _outputs =
[new LogDiagnosticOutput(loggerFactory.CreateLogger<LogDiagnosticOutput>()), ..outputs];
[new LogDiagnosticOutput(loggerFactory.CreateLogger<LogDiagnosticOutput>()), .. outputs];

public DiagnosticsChannel Channel { get; } = new();

Expand All @@ -88,7 +88,8 @@ public class DiagnosticsCollector(ILoggerFactory loggerFactory, IReadOnlyCollect

public Task StartAsync(Cancel ctx)
{
if (_started is not null) return _started;
if (_started is not null)
return _started;
_started = Task.Run(async () =>
{
await Channel.WaitToWrite();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public static class ProcessorDiagnosticExtensions
public static void EmitError(this InlineProcessor processor, int line, int column, int length, string message)
{
var context = processor.GetContext();
if (context.SkipValidation) return;
if (context.SkipValidation)
return;
var d = new Diagnostic
{
Severity = Severity.Error,
Expand All @@ -32,7 +33,8 @@ public static void EmitError(this InlineProcessor processor, int line, int colum
public static void EmitWarning(this InlineProcessor processor, int line, int column, int length, string message)
{
var context = processor.GetContext();
if (context.SkipValidation) return;
if (context.SkipValidation)
return;
var d = new Diagnostic
{
Severity = Severity.Warning,
Expand All @@ -47,7 +49,8 @@ public static void EmitWarning(this InlineProcessor processor, int line, int col

public static void EmitError(this ParserContext context, int line, int column, int length, string message, Exception? e = null)
{
if (context.SkipValidation) return;
if (context.SkipValidation)
return;
var d = new Diagnostic
{
Severity = Severity.Error,
Expand All @@ -62,7 +65,8 @@ public static void EmitError(this ParserContext context, int line, int column, i

public static void EmitWarning(this ParserContext context, int line, int column, int length, string message)
{
if (context.SkipValidation) return;
if (context.SkipValidation)
return;
var d = new Diagnostic
{
Severity = Severity.Warning,
Expand Down Expand Up @@ -99,7 +103,8 @@ public static void EmitWarning(this BuildContext context, IFileInfo file, string

public static void EmitError(this IBlockExtension block, string message, Exception? e = null)
{
if (block.SkipValidation) return;
if (block.SkipValidation)
return;

var d = new Diagnostic
{
Expand All @@ -115,7 +120,8 @@ public static void EmitError(this IBlockExtension block, string message, Excepti

public static void EmitWarning(this IBlockExtension block, string message)
{
if (block.SkipValidation) return;
if (block.SkipValidation)
return;

var d = new Diagnostic
{
Expand Down
5 changes: 3 additions & 2 deletions src/Elastic.Markdown/DocumentationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ ILoggerFactory logger
{
var stateFile = DocumentationSet.OutputStateFile;
stateFile.Refresh();
if (!stateFile.Exists) return null;
if (!stateFile.Exists)
return null;
var contents = stateFile.FileSystem.File.ReadAllText(stateFile.FullName);
return JsonSerializer.Deserialize(contents, SourceGenerationContext.Default.GenerationState);
}
Expand Down Expand Up @@ -177,7 +178,7 @@ private bool CompilationNotNeeded(GenerationState? generationState, out HashSet<
else if (DocumentationSet.LastWrite <= outputSeenChanges)
{
_logger.LogInformation($"No compilation: no changes since last observed: {generationState.LastSeenChanges} "
+ "Pass --force to force a full regeneration");
+ "Pass --force to force a full regeneration");
return true;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Elastic.Markdown/IO/ConfigurationFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public ConfigurationFile(IFileInfo sourceFile, IDirectoryInfo rootPath, BuildCon
break;
}
}
Globs = ImplicitFolders.Select(f=> Glob.Parse($"{f}/*.md")).ToArray();
Globs = ImplicitFolders.Select(f => Glob.Parse($"{f}/*.md")).ToArray();
}

private List<ITocItem> ReadChildren(KeyValuePair<YamlNode, YamlNode> entry, string parentPath)
Expand Down Expand Up @@ -167,7 +167,8 @@ private List<ITocItem> ReadChildren(KeyValuePair<YamlNode, YamlNode> entry, stri
{
found = false;
var file = ReadString(entry);
if (file is null) return null;
if (file is null)
return null;

var path = Path.Combine(_rootPath.FullName, parentPath.TrimStart('/'), file);
if (!_context.ReadFileSystem.FileInfo.New(path).Exists)
Expand Down
7 changes: 4 additions & 3 deletions src/Elastic.Markdown/IO/DocumentationFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public DocumentationFolder(IReadOnlyCollection<ITocItem> toc,
{
var children = folder.Children;
if (children.Count == 0
&& folderLookup.TryGetValue(folder.Path, out var documentationFiles))
&& folderLookup.TryGetValue(folder.Path, out var documentationFiles))
{
children = documentationFiles
.Select(d => new TocFile(d.RelativePath, true, []))
Expand All @@ -61,7 +61,7 @@ public DocumentationFolder(IReadOnlyCollection<ITocItem> toc,
Index ??= FilesInOrder.FirstOrDefault();
if (Index != null)
FilesInOrder = FilesInOrder.Except(new[] { Index }).ToList();
OwnFiles = [..FilesInOrder];
OwnFiles = [.. FilesInOrder];
}

public bool HoldsCurrent(MarkdownFile current) =>
Expand All @@ -71,7 +71,8 @@ public bool HoldsCurrent(MarkdownFile current) =>

public async Task Resolve(Cancel ctx = default)
{
if (_resolved) return;
if (_resolved)
return;

await Parallel.ForEachAsync(FilesInOrder, ctx, async (file, token) => await file.MinimalParse(token));
await Parallel.ForEachAsync(GroupsInOrder, ctx, async (group, token) => await group.Resolve(token));
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Markdown/IO/DocumentationSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public DocumentationSet(BuildContext context)
FlatMappedFiles = Files.ToDictionary(file => file.RelativePath, file => file);
var folderFiles = Files
.GroupBy(file => file.RelativeFolder)
.ToDictionary(g=>g.Key, g=>g.ToArray());
.ToDictionary(g => g.Key, g => g.ToArray());

Tree = new DocumentationFolder(Configuration.TableOfContents, FlatMappedFiles, folderFiles);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Elastic.Markdown/IO/MarkdownFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ private void ReadDocumentInstructions(MarkdownDocument document)
_tableOfContent[t.Slug] = t;

var labels = document.Descendants<DirectiveBlock>()
.Select(b=>b.CrossReferenceName)
.Where(l=>!string.IsNullOrWhiteSpace(l))
.Select(b => b.CrossReferenceName)
.Where(l => !string.IsNullOrWhiteSpace(l))
.Select(_slugHelper.GenerateSlug)
.ToArray();
foreach(var label in labels)
foreach (var label in labels)
{
if (!string.IsNullOrEmpty(label))
_additionalLabels.Add(label);
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Markdown/IO/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private static DirectoryInfo RootDirectoryInfo()
{
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
while (directory != null &&
(directory.GetFiles("*.sln").Length == 0 || directory.GetDirectories(".git").Length == 0))
(directory.GetFiles("*.sln").Length == 0 || directory.GetDirectories(".git").Length == 0))
directory = directory.Parent;
return directory ?? new DirectoryInfo(Directory.GetCurrentDirectory());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public override bool Close(BlockProcessor processor, Block block)

var newSpan = line.Slice.AsSpan()[..callout.SliceStart];
var s = new StringSlice(newSpan.ToString());
lines.Lines[callout.Line -1 ] = new StringLine(ref s);
lines.Lines[callout.Line - 1] = new StringLine(ref s);

}
}
Expand Down Expand Up @@ -178,10 +178,12 @@ private static bool ReplaceSubstitutions(ParserContext context, ReadOnlySpan<cha
{
foreach (var match in matches)
{
if (match.Length == 0) continue;
if (match.Length == 0)
continue;

var startIndex = span.LastIndexOf("<");
if (!inlineCodeAnnotation && startIndex <= 0) continue;
if (!inlineCodeAnnotation && startIndex <= 0)
continue;
if (inlineCodeAnnotation)
{
startIndex = Math.Max(span.LastIndexOf("//"), span.LastIndexOf('#'));
Expand Down
9 changes: 6 additions & 3 deletions src/Elastic.Markdown/Myst/Comments/CommentBlockParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ public override BlockState TryOpen(BlockProcessor processor)
// Move to the content
var headingBlock = new CommentBlock(this)
{
CommentChar = matchingChar, Level = leadingCount, Column = column, Span = { Start = sourcePosition },
CommentChar = matchingChar,
Level = leadingCount,
Column = column,
Span = { Start = sourcePosition },
};

if (processor.TrackTrivia)
Expand All @@ -106,8 +109,8 @@ public override BlockState TryOpen(BlockProcessor processor)
var countClosingTags = 0;
var sourceEnd = processor.Line.End;
for (var i = processor.Line.End;
i >= processor.Line.Start - 1;
i--) // Go up to Start - 1 in order to match the space after the first ###
i >= processor.Line.Start - 1;
i--) // Go up to Start - 1 in order to match the space after the first ###
{
c = processor.Line.Text[i];
if (endState == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Markdown/Myst/Directives/AdmonitionBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AdmonitionBlock(DirectiveBlockParser parser, string admonition, Par
public override string Directive => Admonition;

public string? Classes { get; protected set; }
public bool? DropdownOpen { get; private set; }
public bool? DropdownOpen { get; private set; }

public string Title
{
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Markdown/Myst/Directives/AppliesBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public override void FinalizeAndValidate(ParserContext context)
bool TryGetAvailability(string key, out ProductAvailability? semVersion)
{
semVersion = null;
return Prop(key) is {} v && ProductAvailability.TryParse(v, out semVersion);
return Prop(key) is { } v && ProductAvailability.TryParse(v, out semVersion);
}
}
}
79 changes: 41 additions & 38 deletions src/Elastic.Markdown/Myst/Directives/DirectiveBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,59 +51,60 @@ public abstract class DirectiveBlock(

public abstract string Directive { get; }

public string? CrossReferenceName { get; protected set; }
public string? CrossReferenceName { get; protected set; }

/// <inheritdoc />
public char FencedChar { get; set; }

/// <inheritdoc />
public int OpeningFencedCharCount { get; set; }
/// <inheritdoc />
public int OpeningFencedCharCount { get; set; }

/// <inheritdoc />
public StringSlice TriviaAfterFencedChar { get; set; }
/// <inheritdoc />
public StringSlice TriviaAfterFencedChar { get; set; }

/// <inheritdoc />
public string? Info { get; set; }
/// <inheritdoc />
public string? Info { get; set; }

/// <inheritdoc />
public StringSlice UnescapedInfo { get; set; }
/// <inheritdoc />
public StringSlice UnescapedInfo { get; set; }

/// <inheritdoc />
public StringSlice TriviaAfterInfo { get; set; }
/// <inheritdoc />
public StringSlice TriviaAfterInfo { get; set; }

/// <inheritdoc />
public string? Arguments { get; set; }
/// <inheritdoc />
public string? Arguments { get; set; }

/// <inheritdoc />
public StringSlice UnescapedArguments { get; set; }
/// <inheritdoc />
public StringSlice UnescapedArguments { get; set; }

/// <inheritdoc />
public StringSlice TriviaAfterArguments { get; set; }
/// <inheritdoc />
public StringSlice TriviaAfterArguments { get; set; }

/// <inheritdoc />
public NewLine InfoNewLine { get; set; }
/// <inheritdoc />
public NewLine InfoNewLine { get; set; }

/// <inheritdoc />
public StringSlice TriviaBeforeClosingFence { get; set; }
/// <inheritdoc />
public StringSlice TriviaBeforeClosingFence { get; set; }

/// <inheritdoc />
public int ClosingFencedCharCount { get; set; }
/// <inheritdoc />
public int ClosingFencedCharCount { get; set; }

/// <summary>
/// Allows blocks to finalize setting properties once fully parsed
/// </summary>
/// <param name="context"></param>
public abstract void FinalizeAndValidate(ParserContext context);
/// <summary>
/// Allows blocks to finalize setting properties once fully parsed
/// </summary>
/// <param name="context"></param>
public abstract void FinalizeAndValidate(ParserContext context);

internal void AddProperty(string key, string value)
{
_properties ??= new Dictionary<string, string>();
_properties[key] = value;
}
internal void AddProperty(string key, string value)
{
_properties ??= new Dictionary<string, string>();
_properties[key] = value;
}

protected bool PropBool(params string[] keys)
{
if (Properties is null) return false;
protected bool PropBool(params string[] keys)
{
if (Properties is null)
return false;
var value = Prop(keys);
if (string.IsNullOrEmpty(value))
return keys.Any(k => Properties.ContainsKey(k));
Expand All @@ -113,7 +114,8 @@ protected bool PropBool(params string[] keys)

protected bool? TryPropBool(params string[] keys)
{
if (Properties is null) return null;
if (Properties is null)
return null;
var value = Prop(keys);
if (string.IsNullOrEmpty(value))
return keys.Any(k => Properties.ContainsKey(k)) ? true : null;
Expand All @@ -124,7 +126,8 @@ protected bool PropBool(params string[] keys)

protected string? Prop(params string[] keys)
{
if (Properties is null) return null;
if (Properties is null)
return null;
foreach (var key in keys)
{
if (Properties.TryGetValue(key, out var value))
Expand Down
Loading
Loading