diff --git a/docs/ConsoleLoggerFactory.md b/docs/ConsoleLoggerFactory.md index 7fa35d6..cbd65ed 100644 --- a/docs/ConsoleLoggerFactory.md +++ b/docs/ConsoleLoggerFactory.md @@ -3,6 +3,8 @@ public class ConsoleLoggerFactory : ILoggerFactory ``` +A simple factory for console loggers that format messages in the Summary CLI way. + ## Fields ### Instance ```cs diff --git a/docs/ScanDirectoryPipe.md b/docs/ScanPipe.md similarity index 69% rename from docs/ScanDirectoryPipe.md rename to docs/ScanPipe.md index 307c7bc..8446954 100644 --- a/docs/ScanDirectoryPipe.md +++ b/docs/ScanPipe.md @@ -1,6 +1,6 @@ -# Summary.Pipes.IO.ScanDirectoryPipe +# Summary.Pipes.IO.ScanPipe ```cs -public class ScanDirectoryPipe : IPipe +public class ScanPipe : IPipe ``` A [`IPipe{I,O}`](./IPipe{I,O}.md) that searches specified directory (recursively) for files that match specified pattern. diff --git a/src/Cli/Logging/ConsoleLoggerFactory.cs b/src/Cli/Logging/ConsoleLoggerFactory.cs index 18e9a82..c76faab 100644 --- a/src/Cli/Logging/ConsoleLoggerFactory.cs +++ b/src/Cli/Logging/ConsoleLoggerFactory.cs @@ -3,6 +3,9 @@ namespace Summary.Cli.Logging; +/// +/// A simple factory for console loggers that format messages in the Summary CLI way. +/// public class ConsoleLoggerFactory : ILoggerFactory { private class Logger : ILogger diff --git a/src/Core/Pipelines/SummaryPipeline.cs b/src/Core/Pipelines/SummaryPipeline.cs index 6224ef1..c0d3d20 100644 --- a/src/Core/Pipelines/SummaryPipeline.cs +++ b/src/Core/Pipelines/SummaryPipeline.cs @@ -1,7 +1,6 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Summary.Pipes; -using Summary.Pipes.Filters; namespace Summary.Pipelines; diff --git a/src/Core/Pipes/Filters/FilterMemberPipe.cs b/src/Core/Pipes/Filters/FilterMemberPipe.cs index 303bf44..3611571 100644 --- a/src/Core/Pipes/Filters/FilterMemberPipe.cs +++ b/src/Core/Pipes/Filters/FilterMemberPipe.cs @@ -3,19 +3,14 @@ namespace Summary.Pipes.Filters; /// /// A simple pipe that filters all members inside the document using the specified predicate. /// -public class FilterMemberPipe : IPipe +public class FilterMemberPipe(Predicate p) : IPipe { - private readonly Predicate _p ; - - public FilterMemberPipe(Predicate p) => - _p = p; - public Task Run(Doc input) => Task.FromResult(new Doc(Filtered(input.Members))); private DocMember[] Filtered(DocMember[] members) => members - .Where(x => _p(x)) + .Where(x => p(x)) .Select(Filtered) .ToArray(); diff --git a/src/Core/Pipes/FoldPipe.cs b/src/Core/Pipes/FoldPipe.cs index 4da427c..ecfcc04 100644 --- a/src/Core/Pipes/FoldPipe.cs +++ b/src/Core/Pipes/FoldPipe.cs @@ -3,17 +3,8 @@ /// /// A that aggregates the result of the specified pipe. /// -public class FoldPipe : IPipe +public class FoldPipe(Func fold, O @default) : IPipe { - private readonly O _default; - private readonly Func _fold; - - public FoldPipe(Func fold, O @default) - { - _fold = fold; - _default = @default; - } - public Task Run(O[] input) => - Task.FromResult(input.Length is 0 ? _default : input.Aggregate(_fold)); + Task.FromResult(input.Length is 0 ? @default : input.Aggregate(fold)); } \ No newline at end of file diff --git a/src/Core/Pipes/IO/CleanupDirPipe.cs b/src/Core/Pipes/IO/CleanupDirPipe.cs index b922c20..886ee62 100644 --- a/src/Core/Pipes/IO/CleanupDirPipe.cs +++ b/src/Core/Pipes/IO/CleanupDirPipe.cs @@ -3,19 +3,14 @@ namespace Summary.Pipes.IO; /// /// Cleans up a given directory by deleting and re-creating it. /// -public class CleanupDirPipe : IPipe +public class CleanupDirPipe(string root) : IPipe { - private readonly string _root; - - public CleanupDirPipe(string root) => - _root = root; - public Task Run(I input) { - if (Directory.Exists(_root)) - Directory.Delete(_root, recursive: true); + if (Directory.Exists(root)) + Directory.Delete(root, recursive: true); - Directory.CreateDirectory(_root); + Directory.CreateDirectory(root); return Task.FromResult(input); } diff --git a/src/Core/Pipes/IO/SavePipe.cs b/src/Core/Pipes/IO/SavePipe.cs index 1b89f27..9a7feba 100644 --- a/src/Core/Pipes/IO/SavePipe.cs +++ b/src/Core/Pipes/IO/SavePipe.cs @@ -3,22 +3,13 @@ /// /// A that saves the input to the file. /// -public class SavePipe : IPipe +public class SavePipe(string root, Func file) : IPipe { - private readonly string _root; - private readonly Func _file; - - public SavePipe(string root, Func file) - { - _root = root; - _file = file; - } - public async Task Run(I input) { - var (path, content) = _file(input); + var (path, content) = file(input); - await File.WriteAllTextAsync(Path.Combine(_root, path), content).ConfigureAwait(continueOnCapturedContext: false); + await File.WriteAllTextAsync(Path.Combine(root, path), content).ConfigureAwait(continueOnCapturedContext: false); return Unit.Value; } diff --git a/src/Core/Pipes/IO/ScanDirectoryPipe.cs b/src/Core/Pipes/IO/ScanPipe.cs similarity index 57% rename from src/Core/Pipes/IO/ScanDirectoryPipe.cs rename to src/Core/Pipes/IO/ScanPipe.cs index dd92537..58f613f 100644 --- a/src/Core/Pipes/IO/ScanDirectoryPipe.cs +++ b/src/Core/Pipes/IO/ScanPipe.cs @@ -3,27 +3,18 @@ /// /// A that searches specified directory (recursively) for files that match specified pattern. /// -public class ScanDirectoryPipe : IPipe +public class ScanPipe(string[] sources, string pattern) : IPipe { - private readonly string[] _sources; - private readonly string _pattern; - - public ScanDirectoryPipe(string[] sources, string pattern) - { - _sources = sources; - _pattern = pattern; - } - public async Task Run(Unit _) { // TODO: Consider refactoring this into more proper solution (@j.light). - if (_sources is [var root] && File.Exists(root)) + if (sources is [var root] && File.Exists(root)) return new[] { await File.ReadAllTextAsync(root) }; - var tasks = _sources + var tasks = sources .SelectMany(x => Directory - .EnumerateFiles(x, _pattern, SearchOption.AllDirectories) + .EnumerateFiles(x, pattern, SearchOption.AllDirectories) .Select(x => File.ReadAllTextAsync(x))); return await Task.WhenAll(tasks).ConfigureAwait(false); diff --git a/src/Core/Pipes/Logging/LoggedPipe.cs b/src/Core/Pipes/Logging/LoggedPipe.cs index c2068e2..c9a3a1e 100644 --- a/src/Core/Pipes/Logging/LoggedPipe.cs +++ b/src/Core/Pipes/Logging/LoggedPipe.cs @@ -8,26 +8,15 @@ namespace Summary.Pipes.Logging; /// /// Logging is implemented by simply beginning a new scope with the given message. /// -public class LoggedPipe : IPipe +public class LoggedPipe(IPipe inner, ILogger logger, Func message) : IPipe { - private readonly IPipe _inner; - private readonly ILogger _logger; - private readonly Func _message; - public LoggedPipe(IPipe inner, ILogger logger, string message) : this(inner, logger, _ => message) { } - public LoggedPipe(IPipe inner, ILogger logger, Func message) - { - _inner = inner; - _logger = logger; - _message = message; - } - public Task Run(I input) { - using var _ = _logger.BeginScope(_message(input)); + using var _ = logger.BeginScope(message(input)); - return _inner.Run(input); + return inner.Run(input); } } \ No newline at end of file diff --git a/src/Core/Pipes/TeePipe.cs b/src/Core/Pipes/TeePipe.cs index 1ade7c6..301ce17 100644 --- a/src/Core/Pipes/TeePipe.cs +++ b/src/Core/Pipes/TeePipe.cs @@ -3,22 +3,13 @@ /// /// A that invokes an action on the output of the pipe each time it's executed. /// -public class TeePipe : IPipe +public class TeePipe(IPipe inner, Action tee) : IPipe { - private readonly IPipe _inner; - private readonly Action _tee; - - public TeePipe(IPipe inner, Action tee) - { - _inner = inner; - _tee = tee; - } - public async Task Run(I input) { - var output = await _inner.Run(input).ConfigureAwait(false); + var output = await inner.Run(input).ConfigureAwait(false); - _tee(output); + tee(output); return output; } diff --git a/src/Core/Pipes/ThenForEach.cs b/src/Core/Pipes/ThenForEach.cs index 587a656..b1c3ff0 100644 --- a/src/Core/Pipes/ThenForEach.cs +++ b/src/Core/Pipes/ThenForEach.cs @@ -3,21 +3,12 @@ /// /// A that aggregates the result of the specified pipe. /// -public class ThenForEach : IPipe +public class ThenForEach(IPipe inner, IPipe map) : IPipe { - private readonly IPipe _inner; - private readonly IPipe _map; - - public ThenForEach(IPipe inner, IPipe map) - { - _inner = inner; - _map = map; - } - public async Task Run(I input) { - var os = await _inner.Run(input).ConfigureAwait(false); + var os = await inner.Run(input).ConfigureAwait(false); - return await Task.WhenAll(os.Select(_map.Run).ToArray()).ConfigureAwait(false); + return await Task.WhenAll(os.Select(map.Run).ToArray()).ConfigureAwait(false); } } \ No newline at end of file diff --git a/src/Core/Pipes/ThenPipe.cs b/src/Core/Pipes/ThenPipe.cs index bc45900..5690a63 100644 --- a/src/Core/Pipes/ThenPipe.cs +++ b/src/Core/Pipes/ThenPipe.cs @@ -3,22 +3,13 @@ /// /// A that composes two pipes together. /// -public class ThenPipe : IPipe +public class ThenPipe(IPipe a, IPipe b) : IPipe { - private readonly IPipe _a; - private readonly IPipe _b; - - public ThenPipe(IPipe a, IPipe b) - { - _a = a; - _b = b; - } - public async Task Run(I i) { - var a = await _a.Run(i).ConfigureAwait(false); - var b = await _b.Run(a).ConfigureAwait(false); + var x = await a.Run(i).ConfigureAwait(false); + var y = await b.Run(x).ConfigureAwait(false); - return b; + return y; } } \ No newline at end of file diff --git a/src/Plugins/Roslyn/Roslyn.csproj b/src/Plugins/Roslyn/Roslyn.csproj index 81c2aa8..5c1a612 100644 --- a/src/Plugins/Roslyn/Roslyn.csproj +++ b/src/Plugins/Roslyn/Roslyn.csproj @@ -26,15 +26,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/Plugins/Roslyn/RoslynPipelineExtensions.cs b/src/Plugins/Roslyn/RoslynPipelineExtensions.cs index 7ffd343..2922a50 100644 --- a/src/Plugins/Roslyn/RoslynPipelineExtensions.cs +++ b/src/Plugins/Roslyn/RoslynPipelineExtensions.cs @@ -28,10 +28,10 @@ public static SummaryPipeline UseRoslynParser(this SummaryPipeline self, string /// public static SummaryPipeline UseRoslynParser(this SummaryPipeline self, string[] sources, string pattern = "*.cs") => self.ParseWith(options => - new ScanDirectoryPipe(sources, pattern) + new ScanPipe(sources, pattern) .ThenForEach(new ParseSyntaxTreePipe()) .ThenForEach(new ParseDocPipe()) - .Logged(options.LoggerFactory, $"Parse directories [{sources.Select(x => $"'{x.AsFullPath()}'").Separated(with: ", ")}] with '{pattern}' pattern") + .Logged(options.LoggerFactory, $"Scan [{sources.Select(x => $"'{x.AsFullPath()}'").Separated(with: ", ")}] using '{pattern}' pattern") .Then(new FoldPipe(Doc.Merge, Doc.Empty).Logged(options.LoggerFactory, docs => $"Merge {docs.Length} files")) .Then(new InlineInheritDocPipe().Logged(options.LoggerFactory, "Inline tags"))); } \ No newline at end of file