Skip to content

Commit e20261b

Browse files
committed
Massive simplification by using Datacute.IncrementalGeneratorExtensions
Also changed to use a builder style pattern for the pipeline Combines.
1 parent a238625 commit e20261b

30 files changed

+927
-1148
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,36 @@ jobs:
3535
with:
3636
dotnet-version: '9.0.x'
3737

38+
- name: Get tag for current commit
39+
id: get_tag
40+
# Check for tags when triggered by main branch push (with tag) or direct tag push
41+
# Can't use github.ref_name because it's "main" when pushing branch+tag together
42+
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
43+
uses: olegtarasov/[email protected]
44+
45+
- name: Set Version Profile
46+
run: |
47+
if [[ "${{ steps.get_tag.outputs.tag }}" != "" ]]; then
48+
echo "VERSION_PROFILE=release" >> $GITHUB_ENV
49+
else
50+
echo "VERSION_PROFILE=ci" >> $GITHUB_ENV
51+
fi
52+
3853
- name: Restore dependencies
3954
run: dotnet restore $SOLUTION
4055

4156
- name: Build
42-
run: dotnet build $SOLUTION --configuration $BUILD_CONFIG --no-restore -p:GeneratePackageOnBuild=false
57+
run: dotnet build $SOLUTION --configuration $BUILD_CONFIG --no-restore -p:GeneratePackageOnBuild=false -p:VersionProfile=${{ env.VERSION_PROFILE }}
4358

4459
- name: Run tests
45-
run: dotnet test --configuration $BUILD_CONFIG --no-restore --no-build --verbosity normal
60+
run: dotnet test --configuration $BUILD_CONFIG --no-restore --no-build --verbosity normal -p:VersionProfile=${{ env.VERSION_PROFILE }}
4661

4762
- name: Pack NuGet packages
4863
run: |
49-
dotnet pack $SOLUTION --configuration $BUILD_CONFIG --no-build --output ./artifacts
64+
dotnet pack $SOLUTION --configuration $BUILD_CONFIG --no-build --output ./artifacts -p:VersionProfile=${{ env.VERSION_PROFILE }}
5065
echo "=== Packages created ==="
5166
ls -la ./artifacts/
5267
53-
- name: Get tag for current commit
54-
id: get_tag
55-
# Check for tags when triggered by main branch push (with tag) or direct tag push
56-
# Can't use github.ref_name because it's "main" when pushing branch+tag together
57-
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
58-
uses: olegtarasov/[email protected]
59-
6068
- name: Extract release notes from CHANGELOG.md
6169
if: steps.get_tag.outputs.tag != ''
6270
id: extract_notes

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jobs:
2121
- name: Restore, Build, and Pack
2222
run: |
2323
dotnet restore *.sln
24-
dotnet build *.sln --configuration Release --no-restore -p:ContinuousIntegrationBuild=true -p:GeneratePackageOnBuild=false
25-
dotnet pack *.sln --configuration Release --no-build --output ./artifacts -p:ContinuousIntegrationBuild=true
24+
dotnet build *.sln --configuration Release --no-restore -p:ContinuousIntegrationBuild=true -p:GeneratePackageOnBuild=false -p:VersionProfile=release
25+
dotnet pack *.sln --configuration Release --no-build --output ./artifacts -p:ContinuousIntegrationBuild=true -p:VersionProfile=release
2626
2727
- name: Publish to NuGet
2828
run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate

README.md

Lines changed: 280 additions & 3 deletions
Large diffs are not rendered by default.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using System;
2+
3+
namespace Datacute.SourceGeneratorContext;
4+
5+
/// <summary>
6+
/// Specifies the types of information to include in the generated source context documentation.
7+
/// </summary>
8+
[Flags]
9+
public enum IncludeFlags : uint
10+
{
11+
/// <summary>
12+
/// If no other specific flags are set, a basic summary of the context is included.
13+
/// This flag is often managed internally by the generator to provide a default output.
14+
/// </summary>
15+
Summary = 0,
16+
17+
/// <summary>
18+
/// Includes details about the GeneratorAttributeSyntaxContext.TargetSymbol.
19+
/// </summary>
20+
AttributeContextTargetSymbol = 1U << 0,
21+
22+
/// <summary>
23+
/// Includes details about the GeneratorAttributeSyntaxContext.TargetSymbol when cast to an ITypeSymbol.
24+
/// </summary>
25+
AttributeContextTypeSymbol = 1U << 1,
26+
27+
/// <summary>
28+
/// Includes details about the GeneratorAttributeSyntaxContext.TargetSymbol when cast to an INamedTypeSymbol.
29+
/// </summary>
30+
AttributeContextNamedTypeSymbol = 1U << 2,
31+
32+
/// <summary>
33+
/// Includes details about the GeneratorAttributeSyntaxContext.TargetNode.
34+
/// </summary>
35+
AttributeContextTargetNode = 1U << 3,
36+
37+
/// <summary>
38+
/// Includes details about the GeneratorAttributeSyntaxContext.Attributes.
39+
/// </summary>
40+
AttributeContextAttributes = 1U << 4,
41+
42+
/// <summary>
43+
/// Includes details about all attributes applied to the target symbol (using GetAttributes()).
44+
/// </summary>
45+
AttributeContextAllAttributes = 1U << 5,
46+
47+
/// <summary>
48+
/// Includes details from the AnalyzerConfigOptionsProvider's GlobalOptions.
49+
/// </summary>
50+
GlobalOptions = 1U << 6,
51+
52+
/// <summary>
53+
/// Includes general details about the Compilation.
54+
/// </summary>
55+
Compilation = 1U << 7,
56+
57+
/// <summary>
58+
/// Includes details about the Compilation's options.
59+
/// </summary>
60+
CompilationOptions = 1U << 8,
61+
62+
/// <summary>
63+
/// Includes details about the Compilation's assembly.
64+
/// </summary>
65+
CompilationAssembly = 1U << 9,
66+
67+
/// <summary>
68+
/// Includes counts and names of Compilation's references (e.g., References, DirectiveReferences).
69+
/// </summary>
70+
CompilationReferences = 1U << 10,
71+
72+
/// <summary>
73+
/// Includes details about the ParseOptionsProvider's ParseOptions.
74+
/// </summary>
75+
ParseOptions = 1U << 11,
76+
77+
/// <summary>
78+
/// Includes details about AdditionalTextsProvider's AdditionalText entries.
79+
/// </summary>
80+
AdditionalTexts = 1U << 12,
81+
82+
/// <summary>
83+
/// Includes details about AdditionalTextsProvider's AdditionalText options (from AnalyzerConfigOptions).
84+
/// </summary>
85+
AdditionalTextsOptions = 1U << 13,
86+
87+
/// <summary>
88+
/// Includes details about MetadataReferencesProvider's MetadataReference entries.
89+
/// </summary>
90+
MetadataReferences = 1U << 14,
91+
92+
/// <summary>
93+
/// Includes all available details about the source generation context.
94+
/// </summary>
95+
All = ~0U
96+
97+
}

SourceGeneratorContext.Attribute/SourceGeneratorContextAttribute.cs

Lines changed: 6 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -20,94 +20,19 @@ public class SourceGeneratorContextAttribute : Attribute
2020
/// There is a huge amount of information available, but Visual Studio does not scroll doc-comments.
2121
/// So either IncludeAll and view the generated source, or set one of the named parameters to control what gets output:
2222
/// <code>
23-
/// [SourceGeneratorContext(IncludeAll = true)]
23+
/// [SourceGeneratorContext(IncludeFlags.All)]
2424
/// internal partial class Example;
2525
/// </code>
2626
/// </remarks>
27-
public SourceGeneratorContextAttribute()
27+
public SourceGeneratorContextAttribute(IncludeFlags flags = IncludeFlags.Summary)
2828
{
29+
IncludeFlags = flags;
2930
}
3031

3132
/// <summary>
32-
/// Set to true to include all available details.
33+
/// Flags to control what information is included in the generated doc-comments.
3334
/// </summary>
34-
public bool IncludeAll { get; set; }
35-
36-
/// <summary>
37-
/// Set to true to include the GeneratorAttributeSyntaxContext.TargetSymbol details.
38-
/// </summary>
39-
public bool IncludeAttributeContextTargetSymbol { get; set; }
40-
41-
/// <summary>
42-
/// Set to true to include the GeneratorAttributeSyntaxContext.TargetSymbol as ITypeSymbol details.
43-
/// </summary>
44-
public bool IncludeAttributeContextTypeSymbol { get; set; }
45-
46-
/// <summary>
47-
/// Set to true to include the GeneratorAttributeSyntaxContext.TargetSymbol as INamedTypeSymbol details.
48-
/// </summary>
49-
public bool IncludeAttributeContextNamedTypeSymbol { get; set; }
50-
51-
/// <summary>
52-
/// Set to true to include the GeneratorAttributeSyntaxContext.TargetNode details.
53-
/// </summary>
54-
public bool IncludeAttributeContextTargetNode { get; set; }
55-
56-
/// <summary>
57-
/// Set to true to include the GeneratorAttributeSyntaxContext.Attributes details.
58-
/// </summary>
59-
public bool IncludeAttributeContextAttributes { get; set; }
60-
61-
/// <summary>
62-
/// Set to true to include the GeneratorAttributeSyntaxContext.GetAttributes() details.
63-
/// </summary>
64-
public bool IncludeAttributeContextAllAttributes { get; set; }
65-
66-
/// <summary>
67-
/// Set to true to include the AnalyzerConfigOptionsProvider's GlobalOptions details.
68-
/// </summary>
69-
public bool IncludeGlobalOptions { get; set; }
70-
71-
/// <summary>
72-
/// Set to true to include the CompilationProvider's Compilation details.
73-
/// </summary>
74-
public bool IncludeCompilation { get; set; }
75-
76-
/// <summary>
77-
/// Set to true to include the CompilationProvider's Compilation.Options details.
78-
/// </summary>
79-
public bool IncludeCompilationOptions { get; set; }
80-
81-
/// <summary>
82-
/// Set to true to include the CompilationProvider's Compilation.Assembly details.
83-
/// </summary>
84-
public bool IncludeCompilationAssembly { get; set; }
85-
86-
/// <summary>
87-
/// Set to true to include the Counts of CompilationProvider's Compilation.References, Compilation.DirectiveReferences, Compilation.ExternalReferences, and Compilation.ReferencedAssemblyNames.
88-
/// </summary>
89-
public bool IncludeCompilationReferences { get; set; }
90-
91-
/// <summary>
92-
/// Set to true to include the ParseOptionsProvider's ParseOptions details.
93-
/// </summary>
94-
public bool IncludeParseOptions { get; set; }
95-
96-
/// <summary>
97-
/// Set to true to include the AdditionalTextsProvider's AdditionalText details.
98-
/// </summary>
99-
public bool IncludeAdditionalTexts { get; set; }
100-
101-
/// <summary>
102-
/// Set to true to include the AdditionalTextsProvider's AdditionalText details combined with AnalyzerConfigOptionsProvider's AnalyzerConfigOptions for the AdditionalText.
103-
/// </summary>
104-
public bool IncludeAdditionalTextsOptions { get; set; }
105-
106-
/// <summary>
107-
/// Set to true to include the MetadataReferencesProvider's MetadataReference details.
108-
/// </summary>
109-
public bool IncludeMetadataReferences { get; set; }
110-
35+
public IncludeFlags IncludeFlags { get; set; }
11136

11237
#region Demonstration purposes only
11338

@@ -123,8 +48,7 @@ public SourceGeneratorContextAttribute()
12348
/// <param name="exampleOptionalParameter"></param>
12449
public
12550
SourceGeneratorContextAttribute(
126-
string? exampleOptionalParameter =
127-
null) // only used for demonstrating working with Constructor Arguments
51+
string exampleOptionalParameter) // only used for demonstrating working with Constructor Arguments
12852
{
12953
// The constructor arguments do not need to be assigned to fields or properties
13054
// as the source of the supplied values is what is available to the source generator

SourceGeneratorContext.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1515
Directory.Build.props = Directory.Build.props
1616
LICENSE = LICENSE
1717
version.props = version.props
18+
global.json = global.json
1819
EndProjectSection
1920
EndProject
2021
Global

SourceGeneratorContext/AdditionalTextDescription.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace Datacute.SourceGeneratorContext;
66

7-
public readonly struct AdditionalTextDescription
7+
public readonly record struct AdditionalTextDescription
88
{
99
public readonly string DocComments;
1010
public readonly string OptionsComments;
1111

12-
public AdditionalTextDescription(AdditionalText additionalText, AnalyzerConfigOptions? options = null)
12+
private AdditionalTextDescription(AdditionalText additionalText, AnalyzerConfigOptions? options = null)
1313
{
1414
var sb = new StringBuilder();
1515
sb.AddComment("Path", additionalText.Path);
@@ -36,16 +36,14 @@ public AdditionalTextDescription(AdditionalText additionalText, AnalyzerConfigOp
3636
OptionsComments = sb.ToString();
3737
}
3838

39-
public static AdditionalTextDescription Select(AdditionalText additionalText, CancellationToken token)
39+
public static AdditionalTextDescription Selector(AdditionalText additionalText, CancellationToken token)
4040
{
4141
token.ThrowIfCancellationRequested();
4242
return new AdditionalTextDescription(additionalText);
4343
}
4444

45-
public static AdditionalTextDescription Select((AdditionalText additionalText, AnalyzerConfigOptionsProvider optionsProvider) args, CancellationToken token)
45+
public static AdditionalTextDescription Selector((AdditionalText additionalText, AnalyzerConfigOptionsProvider optionsProvider) args, CancellationToken token)
4646
{
47-
LightweightTrace.Add(TrackingNames.AdditionalTextDescription_Select);
48-
4947
token.ThrowIfCancellationRequested();
5048
var options = args.optionsProvider.GetOptions(args.additionalText);
5149
return new AdditionalTextDescription(args.additionalText, options);

SourceGeneratorContext/AnalyzerConfigOptionsDescription.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ public AnalyzerConfigOptionsDescription(AnalyzerConfigOptions options)
1818
DocComments = sb.ToString();
1919
}
2020

21-
public static AnalyzerConfigOptionsDescription Select(AnalyzerConfigOptionsProvider provider, CancellationToken token)
21+
public static AnalyzerConfigOptionsDescription Selector(AnalyzerConfigOptionsProvider provider, CancellationToken token)
2222
{
23-
LightweightTrace.Add(TrackingNames.AnalyzerConfigOptionsDescription_Select);
24-
2523
token.ThrowIfCancellationRequested();
2624
return new AnalyzerConfigOptionsDescription(provider.GlobalOptions);
2725
}

0 commit comments

Comments
 (0)