From f5cf3b96cd8f8c5d07e9fde90e68b2c349c7ce46 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Sun, 1 Jan 2023 18:34:49 -0300 Subject: [PATCH] Fix logic for determining default text resources We cannot use semicolons for properties passed to analyzers, we always lose all items except for the first one. So we switch to a pipe instead. The existing logic was also not accurate since it should consider file extensions, not file name. --- src/Directory.props | 1 + src/ThisAssembly.Resources/ResourcesGenerator.cs | 15 +++++++++------ .../ThisAssembly.Resources.props | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Directory.props b/src/Directory.props index ea61fb05..b0630fe3 100644 --- a/src/Directory.props +++ b/src/Directory.props @@ -6,6 +6,7 @@ true analyzers/dotnet/cs false + https://api.nuget.org/v3/index.json $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\nugetizer\bin'));$(RestoreSources) https://clarius.org/ThisAssembly diff --git a/src/ThisAssembly.Resources/ResourcesGenerator.cs b/src/ThisAssembly.Resources/ResourcesGenerator.cs index ea1e3d60..3cd1ccf7 100644 --- a/src/ThisAssembly.Resources/ResourcesGenerator.cs +++ b/src/ThisAssembly.Resources/ResourcesGenerator.cs @@ -1,5 +1,5 @@ using System; -using System.Collections.Immutable; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -35,8 +35,11 @@ public void Initialize(IncrementalGeneratorInitializationContext context) .Combine(context.AnalyzerConfigOptionsProvider .Select((p, _) => { - p.GlobalOptions.TryGetValue("build_property.EmbeddedResourceStringExtensions", out var extensions); - return extensions!; + if (!p.GlobalOptions.TryGetValue("build_property.EmbeddedResourceStringExtensions", out var extensions) || + extensions == null) + return new HashSet(); + + return new HashSet(extensions.Split('|'), StringComparer.OrdinalIgnoreCase); })); context.RegisterSourceOutput( @@ -44,15 +47,15 @@ public void Initialize(IncrementalGeneratorInitializationContext context) GenerateSource); } - static void GenerateSource(SourceProductionContext spc, ((string resourceName, string? kind, string? comment), string extensions) arg2) + static void GenerateSource(SourceProductionContext spc, ((string resourceName, string? kind, string? comment), HashSet extensions) arg2) { var ((resourceName, kind, comment), extensions) = arg2; var file = "CSharp.sbntxt"; var template = Template.Parse(EmbeddedResource.GetContent(file), file); - var isText = kind != null && kind.Equals("text", StringComparison.OrdinalIgnoreCase) - || extensions.Split(';').Contains(Path.GetFileName(resourceName)); + var isText = kind?.Equals("text", StringComparison.OrdinalIgnoreCase) == true || + extensions.Contains(Path.GetExtension(resourceName)); var root = Area.Load(new Resource(resourceName, comment, isText)); var model = new Model(root); diff --git a/src/ThisAssembly.Resources/ThisAssembly.Resources.props b/src/ThisAssembly.Resources/ThisAssembly.Resources.props index d4a06db1..2107582d 100644 --- a/src/ThisAssembly.Resources/ThisAssembly.Resources.props +++ b/src/ThisAssembly.Resources/ThisAssembly.Resources.props @@ -1,7 +1,7 @@ - .txt;.cs;.sql;.json;.md; + .txt|.cs|.sql|.json|.md;