From 7c7087a918f722c6f14eea8d8e2bd637dcbb9f1f Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 20 Jan 2024 13:08:55 +0900 Subject: [PATCH 1/2] misc --- Compiler/BebopCompiler.cs | 2 -- Compiler/Commands/BuildCommand.cs | 11 ++++++++--- Compiler/Options/DiagnosticFormatOption.cs | 1 - Compiler/Program.cs | 3 +-- Compiler/Watcher.cs | 7 ++++++- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Compiler/BebopCompiler.cs b/Compiler/BebopCompiler.cs index 33b84541..2af66b0a 100644 --- a/Compiler/BebopCompiler.cs +++ b/Compiler/BebopCompiler.cs @@ -7,7 +7,6 @@ using Core.Exceptions; using Core.Parser; using Core.Generators; -using Core.Logging; using System.IO; using Core; @@ -58,7 +57,6 @@ public static void EmitGeneratedFiles(List generatedFiles, BebopC public async ValueTask BuildAsync(GeneratorConfig generatorConfig, BebopSchema schema, BebopConfig config, CancellationToken cancellationToken) { - var (warnings, errors) = GetSchemaDiagnostics(schema, config.SupressedWarningCodes); if (!Host.TryGetGenerator(generatorConfig.Alias, out var generator)) { throw new CompilerException($"Could not find generator with alias '{generatorConfig.Alias}'."); diff --git a/Compiler/Commands/BuildCommand.cs b/Compiler/Commands/BuildCommand.cs index cf0a64c0..a7d2f43c 100644 --- a/Compiler/Commands/BuildCommand.cs +++ b/Compiler/Commands/BuildCommand.cs @@ -16,10 +16,10 @@ public class BuildCommand : CliCommand { public BuildCommand() : base(CliStrings.BuildCommand, "Build schemas into one or more target languages.") { - SetAction(HandleCommand); + SetAction(HandleCommandAsync); } - private async Task HandleCommand(ParseResult result, CancellationToken cancellationToken) + private async Task HandleCommandAsync(ParseResult result, CancellationToken cancellationToken) { var config = result.GetValue(CliStrings.ConfigFlag)!; @@ -47,7 +47,12 @@ private async Task HandleCommand(ParseResult result, CancellationToken canc using var fs = File.Open(tempFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); using var standardInput = Console.OpenStandardInput(); // dont use async as wasi currently has threading issues - standardInput.CopyTo(fs); +#if !WASI_WASM_BUILD + await standardInput.CopyToAsync(fs, cancellationToken); +#else + standardInput.CopyTo(fs); +#endif + fs.Seek(0, SeekOrigin.Begin); schema = compiler.ParseSchema([tempFilePath]); } diff --git a/Compiler/Options/DiagnosticFormatOption.cs b/Compiler/Options/DiagnosticFormatOption.cs index ba91e015..bbe89032 100644 --- a/Compiler/Options/DiagnosticFormatOption.cs +++ b/Compiler/Options/DiagnosticFormatOption.cs @@ -62,7 +62,6 @@ private static LogFormatter Parse(string? token) { "enhanced" => LogFormatter.Enhanced, "json" => LogFormatter.JSON, - "structured" => LogFormatter.Structured, "msbuild" => LogFormatter.MSBuild, _ => throw new ArgumentException($"Invalid diagnostic format '{token}'."), }; diff --git a/Compiler/Program.cs b/Compiler/Program.cs index bf4c169f..f43a0ecd 100644 --- a/Compiler/Program.cs +++ b/Compiler/Program.cs @@ -9,7 +9,6 @@ using System.Text.Json; using Core.Exceptions; using Compiler; -using System.IO; if (RuntimeInformation.OSArchitecture is Architecture.Wasm) { @@ -52,13 +51,13 @@ new NoWarnOption(), new PreserveWatchOutputOption(), }, + #endif new ConvertCommand() { new FromOption(), new ToOption(), new DryRunOption(), }, - #endif }; diff --git a/Compiler/Watcher.cs b/Compiler/Watcher.cs index 829bc6d5..028e3371 100644 --- a/Compiler/Watcher.cs +++ b/Compiler/Watcher.cs @@ -5,7 +5,6 @@ using System.Threading; using System.Threading.Tasks; using Compiler; -using Core.Generators; using Core.Logging; using Core.Meta; using Microsoft.Extensions.FileSystemGlobbing; @@ -135,7 +134,9 @@ public void AddExcludeFiles(List excludeFiles) /// /// Handles the Renamed event of the FileSystemWatcher. /// +#pragma warning disable VSTHRD100 // Avoid async void methods private async void FileRenamed(object sender, RenamedEventArgs e) +#pragma warning restore VSTHRD100 // Avoid async void methods { string oldFullPath = Path.GetFullPath(e.OldFullPath); string newFullPath = Path.GetFullPath(e.FullPath); @@ -219,7 +220,9 @@ private async void FileRenamed(object sender, RenamedEventArgs e) /// /// Handles the Deleted event of the FileSystemWatcher. /// +#pragma warning disable VSTHRD100 // Avoid async void methods private async void FileDeleted(object sender, FileSystemEventArgs e) +#pragma warning restore VSTHRD100 // Avoid async void methods { if (!Path.GetExtension(e.FullPath).Equals(".bop", StringComparison.InvariantCultureIgnoreCase) || IsPathExcluded(e.FullPath)) { @@ -252,7 +255,9 @@ private void FileCreated(object sender, FileSystemEventArgs e) /// /// Handles the Changed event of the FileSystemWatcher. /// +#pragma warning disable VSTHRD100 // Avoid async void methods private async void FileChanged(object sender, FileSystemEventArgs e) +#pragma warning restore VSTHRD100 // Avoid async void methods { if (!Path.GetExtension(e.FullPath).Equals(".bop", StringComparison.InvariantCultureIgnoreCase) || IsPathExcluded(e.FullPath)) { From 07c92e229536d93b110e6d8df88b6bf201cff172 Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 20 Jan 2024 13:09:09 +0900 Subject: [PATCH 2/2] remove structured logging --- Core/Logging/DiagnosticLogger.Enhanced.cs | 15 +++++++++------ Core/Logging/DiagnosticLogger.Format.cs | 7 ------- Core/Logging/DiagnosticLogger.cs | 6 ------ Core/Logging/LogFormatter.cs | 6 ------ 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/Core/Logging/DiagnosticLogger.Enhanced.cs b/Core/Logging/DiagnosticLogger.Enhanced.cs index d2265c12..83ae1faa 100644 --- a/Core/Logging/DiagnosticLogger.Enhanced.cs +++ b/Core/Logging/DiagnosticLogger.Enhanced.cs @@ -34,11 +34,11 @@ private void RenderEnhancedSpanErrors(List exs) foreach (var ex in group) { var diagnostic = new Diagnostic(ex.Severity, ex.Message, ex.ErrorCode, ex.Span); - if (diagnostic.Severity == Severity.Warning) + if (diagnostic is { Severity: Severity.Warning, Span: not null }) { errataDiagnostic.WithLabel(new Label(fileName, GetRangeFromSpan(schemaSource, diagnostic.Span.Value), diagnostic.Message).WithColor(Color.Yellow)); } - else if (diagnostic.Severity == Severity.Error) + else if (diagnostic is { Severity: Severity.Error, Span: not null }) { errataDiagnostic.WithLabel(new Label(fileName, GetRangeFromSpan(schemaSource, diagnostic.Span.Value), diagnostic.Message).WithColor(Color.Red)); } @@ -74,15 +74,18 @@ private void RenderEnhancedException(Exception ex, int errorCode) _err.Write(filePath); _err.WriteLine(); } - if (ex is { StackTrace: null } and { InnerException: not null}) + if (ex is { StackTrace: null } and { InnerException: not null }) { _err.WriteLine(); _err.MarkupLine("[red bold]Inner Exception:[/]"); - if (_traceEnabled) { + if (_traceEnabled) + { _err.WriteException(ex.InnerException); - } else { + } + else + { _err.MarkupLine($"[white]{ex.InnerException.Message}[/]"); - + } } if (_traceEnabled && !string.IsNullOrWhiteSpace(ex.StackTrace)) diff --git a/Core/Logging/DiagnosticLogger.Format.cs b/Core/Logging/DiagnosticLogger.Format.cs index f350762f..1664ef65 100644 --- a/Core/Logging/DiagnosticLogger.Format.cs +++ b/Core/Logging/DiagnosticLogger.Format.cs @@ -1,11 +1,7 @@ using System; using System.Text.Json; -using System.Text.Json.Serialization; using Core.Exceptions; using Core.Meta; -using Core.Meta.Extensions; -using System.Text.Json.Serialization.Metadata; -using Spectre.Console; namespace Core.Logging; @@ -24,9 +20,6 @@ private string FormatDiagnostic(Diagnostic diagnostic) case LogFormatter.MSBuild: var where = span == null ? ReservedWords.CompilerName : $"{span?.FileName}({span?.StartColonString(',')})"; return $"{where} : {diagnostic.Severity.ToString().ToLowerInvariant()} BOP{diagnostic.ErrorCode}: {message}"; - case LogFormatter.Structured: - where = span == null ? "" : $"Issue located in '{span?.FileName}' at {span?.StartColonString()}: "; - return $"[{DateTime.Now}][Compiler][{diagnostic.Severity}] {where}{message}"; case LogFormatter.JSON: return JsonSerializer.Serialize(diagnostic, JsonContext.Default.Diagnostic); case LogFormatter.Enhanced: diff --git a/Core/Logging/DiagnosticLogger.cs b/Core/Logging/DiagnosticLogger.cs index d33ce94d..1105d577 100644 --- a/Core/Logging/DiagnosticLogger.cs +++ b/Core/Logging/DiagnosticLogger.cs @@ -14,7 +14,6 @@ public partial class DiagnosticLogger private static DiagnosticLogger? _instance; private LogFormatter _formatter; private bool _traceEnabled; - private bool _diagnosticsSupressed; private readonly IAnsiConsole _out; private readonly IAnsiConsole _err; public IAnsiConsole Out => _out; @@ -206,9 +205,4 @@ public void WriteErrorLine(string message) { _err.WriteLine(message); } - - public void SuppressDiagnostics() - { - _diagnosticsSupressed = true; - } } diff --git a/Core/Logging/LogFormatter.cs b/Core/Logging/LogFormatter.cs index 269f14e6..adbbe8f1 100644 --- a/Core/Logging/LogFormatter.cs +++ b/Core/Logging/LogFormatter.cs @@ -9,12 +9,6 @@ namespace Core.Logging /// public enum LogFormatter : uint { - /// - /// Data is formatted using structured logging. This is the default formatter. - /// - [Obsolete("Use Enhanced instead of Structure")] - Structured, - /// /// Data is formatted for MSBuild comparability. View the ///