Skip to content

Commit fda401e

Browse files
authored
Merge pull request #1 from datacute/release/0.0.1-alpha
Release/0.0.1 alpha
2 parents e92cb52 + 9ea2cdd commit fda401e

33 files changed

+2187
-14
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root = true
2+
3+
[*]
4+
# This only shows when calling AnalyzerConfigOptionsProvider.GetOptions(additionalText)
5+
example_editorconfig_value = true

.github/workflows/ci.yml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323

2424
env:
2525
BUILD_CONFIG: 'Release'
26-
SOLUTION: 'SourceGeneratorContext.sln'
26+
SOLUTION: '*.sln'
2727

2828
runs-on: ubuntu-latest
2929

@@ -33,7 +33,7 @@ jobs:
3333
- name: Setup .NET
3434
uses: actions/setup-dotnet@v4
3535
with:
36-
dotnet-version: '8.0.x'
36+
dotnet-version: '9.0.x'
3737

3838
- name: Restore dependencies
3939
run: dotnet restore $SOLUTION
@@ -44,27 +44,32 @@ jobs:
4444
- name: Run tests
4545
run: dotnet test --configuration $BUILD_CONFIG --no-restore --no-build --verbosity normal
4646

47+
- name: Pack NuGet packages
48+
run: |
49+
dotnet pack $SOLUTION --configuration $BUILD_CONFIG --no-build --output ./artifacts
50+
echo "=== Packages created ==="
51+
ls -la ./artifacts/
52+
4753
- name: Get tag for current commit
4854
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
4957
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
50-
run: |
51-
TAG=$(git tag --points-at HEAD | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
52-
echo "tag=$TAG" >> $GITHUB_OUTPUT
53-
echo "Found tag: $TAG"
54-
55-
- name: Pack NuGet package
56-
if: steps.get_tag.outputs.tag != ''
57-
run: dotnet pack $SOLUTION --configuration $BUILD_CONFIG --no-build --output ./artifacts
58+
uses: olegtarasov/get-tag@v2.1.4
5859

59-
- name: Publish to NuGet
60+
- name: Extract release notes from CHANGELOG.md
6061
if: steps.get_tag.outputs.tag != ''
61-
run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
62+
id: extract_notes
63+
uses: mindsers/changelog-reader-action@v2
64+
with:
65+
version: ${{ steps.get_tag.outputs.tag }}
66+
path: ./CHANGELOG.md
6267

6368
- name: Create GitHub Release
6469
if: steps.get_tag.outputs.tag != ''
6570
uses: softprops/action-gh-release@v1
6671
with:
6772
tag_name: ${{ steps.get_tag.outputs.tag }}
68-
generate_release_notes: true
73+
body: ${{ steps.extract_notes.outputs.changes }}
6974
env:
7075
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/publish.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Publish to NuGet
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup .NET
17+
uses: actions/setup-dotnet@v4
18+
with:
19+
dotnet-version: '9.0.x'
20+
21+
- name: Restore, Build, and Pack
22+
run: |
23+
dotnet restore *.sln
24+
dotnet build *.sln --configuration Release --no-restore
25+
dotnet pack *.sln --configuration Release --no-build --output ./artifacts
26+
27+
- name: Publish to NuGet
28+
run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate

.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,13 @@ CodeCoverage/
5151
# NUnit
5252
*.VisualState.xml
5353
TestResult.xml
54-
nunit-*.xml
54+
nunit-*.xml
55+
56+
# Visual Studio Code
57+
.vscode/
58+
59+
# Rider
60+
.idea/
61+
62+
# Visual Studio
63+
.vs/

CHANGELOG.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
- `SourceGeneratorContext` library to help creators of source generators.
12+
- `[SourceGeneratorContext]` attribute to mark partial classes for generation.
13+
- Generate doc-comments to partial classes showing different portions of the context available to source generators.
14+
- IncludeAll
15+
- include all available details.
16+
- IncludeAttributeContextTargetSymbol
17+
- GeneratorAttributeSyntaxContext.TargetSymbol details
18+
- IncludeAttributeContextTypeSymbol
19+
- GeneratorAttributeSyntaxContext.TargetSymbol as ITypeSymbol details
20+
- IncludeAttributeContextNamedTypeSymbol
21+
- GeneratorAttributeSyntaxContext.TargetSymbol as INamedTypeSymbol details
22+
- IncludeAttributeContextTargetNode
23+
- GeneratorAttributeSyntaxContext.TargetNode details
24+
- IncludeAttributeContextAttributes
25+
- GeneratorAttributeSyntaxContext.Attributes details
26+
- IncludeAttributeContextAllAttributes
27+
- GeneratorAttributeSyntaxContext.GetAttributes() details
28+
- IncludeGlobalOptions
29+
- AnalyzerConfigOptionsProvider's GlobalOptions details
30+
- IncludeCompilation
31+
- CompilationProvider's Compilation details
32+
- IncludeCompilationOptions
33+
- CompilationProvider's Compilation.Options details
34+
- IncludeCompilationAssembly
35+
- CompilationProvider's Compilation.Assembly details
36+
- IncludeCompilationReferences
37+
- Counts of CompilationProvider's:
38+
- Compilation.References
39+
- Compilation.DirectiveReferences
40+
- Compilation.ExternalReferences
41+
- Compilation.ReferencedAssemblyNames
42+
- IncludeParseOptions
43+
- ParseOptionsProvider's ParseOptions details
44+
- IncludeAdditionalTexts
45+
- AdditionalTextsProvider's AdditionalText details
46+
- IncludeAdditionalTextsOptions
47+
- AdditionalTextsProvider's AdditionalText details combined with AnalyzerConfigOptionsProvider's AnalyzerConfigOptions for the AdditionalText
48+
- IncludeMetadataReferences
49+
- MetadataReferencesProvider's MetadataReference details
50+
- Diagnostic log of the source generation process and timing included.
51+
52+
[Unreleased]: https://github.com/datacute/SourceGeneratorContext/compare/main...develop

Directory.Build.props

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project>
2+
3+
<Import Project="version.props" />
4+
5+
<PropertyGroup>
6+
<Authors>Stephen Denne</Authors>
7+
<Copyright>Copyright © Stephen Denne 2024, 2025</Copyright>
8+
<Company>Datacute</Company>
9+
<PackageProjectUrl>https://github.com/datacute/SourceGeneratorContext</PackageProjectUrl>
10+
<PackageReleaseNotes>See full release notes and changelog: $(PackageProjectUrl)/blob/main/CHANGELOG.md</PackageReleaseNotes>
11+
<CheckEolTargetFramework>false</CheckEolTargetFramework>
12+
</PropertyGroup>
13+
14+
<PropertyGroup>
15+
<NoPackageAnalysis>true</NoPackageAnalysis>
16+
<PackageOutputPath>$(MSBuildThisFileDirectory)\artifacts</PackageOutputPath>
17+
</PropertyGroup>
18+
19+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<LangVersion>12</LangVersion>
6+
<AssemblyName>Datacute.SourceGeneratorContext.Attribute</AssemblyName>
7+
<RootNamespace>Datacute.SourceGeneratorContext</RootNamespace>
8+
<Nullable>enable</Nullable>
9+
<AssemblyVersion>1.0.0</AssemblyVersion>
10+
</PropertyGroup>
11+
12+
<PropertyGroup>
13+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
14+
</PropertyGroup>
15+
16+
</Project>
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
using System;
2+
// ReSharper disable UnusedAutoPropertyAccessor.Global Properties getters are not used as the source generator reads the source code.
3+
// ReSharper disable UnusedParameter.Local Unused parameters are used to demonstrate behaviour.
4+
5+
namespace Datacute.SourceGeneratorContext;
6+
7+
/// <summary>
8+
/// Add this attribute to a partial class to generate doc-comments detailing the source generation context.
9+
/// </summary>
10+
[System.Diagnostics.Conditional("DATACUTE_SOURCEGENERATORCONTEXTATTRIBUTE_USAGES")]
11+
[AttributeUsage(
12+
validOn: AttributeTargets.Class |
13+
AttributeTargets.Interface |
14+
AttributeTargets.Struct, // Method and Property should be allowed too
15+
Inherited = true, // Inherited to show how SyntaxProvider.ForAttributeWithMetadataName doesn't support inheritance
16+
AllowMultiple = true)] // AllowMultiple to show the differences when multiple attributes are applied
17+
public class SourceGeneratorContextAttribute : Attribute
18+
{
19+
/// <remarks>
20+
/// There is a huge amount of information available, but Visual Studio does not scroll doc-comments.
21+
/// So either IncludeAll and view the generated source, or set one of the named parameters to control what gets output:
22+
/// <code>
23+
/// [SourceGeneratorContext(IncludeAll = true)]
24+
/// internal partial class Example;
25+
/// </code>
26+
/// </remarks>
27+
public SourceGeneratorContextAttribute()
28+
{
29+
}
30+
31+
/// <summary>
32+
/// Set to true to include all available details.
33+
/// </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+
111+
112+
#region Demonstration purposes only
113+
114+
/// <summary>
115+
/// Example of a named parameter.
116+
/// </summary>
117+
public string ExampleNamedParameter { get; set; } =
118+
string.Empty; // only used for demonstrating working with Named Parameters
119+
120+
/// <summary>
121+
/// Example of an optional parameter.
122+
/// </summary>
123+
/// <param name="exampleOptionalParameter"></param>
124+
public
125+
SourceGeneratorContextAttribute(
126+
string? exampleOptionalParameter =
127+
null) // only used for demonstrating working with Constructor Arguments
128+
{
129+
// The constructor arguments do not need to be assigned to fields or properties
130+
// as the source of the supplied values is what is available to the source generator
131+
}
132+
133+
#endregion
134+
}

SourceGeneratorContext.sln

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.13.35825.156 d17.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceGeneratorContext", "SourceGeneratorContext\SourceGeneratorContext.csproj", "{DB6CCC3F-D197-48F7-B166-E9194233939D}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceGeneratorContext.Attribute", "SourceGeneratorContext.Attribute\SourceGeneratorContext.Attribute.csproj", "{394AEA19-BF98-4427-BE95-BBD90A7D65A5}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceGeneratorContextExample", "SourceGeneratorContextExample\SourceGeneratorContextExample.csproj", "{56E79762-6BB4-4042-9EAB-2D819C2FDAB0}"
11+
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8EC462FD-D22E-90A8-E5CE-7E832BA40C5D}"
13+
ProjectSection(SolutionItems) = preProject
14+
CHANGELOG.md = CHANGELOG.md
15+
Directory.Build.props = Directory.Build.props
16+
LICENSE = LICENSE
17+
version.props = version.props
18+
EndProjectSection
19+
EndProject
20+
Global
21+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
22+
Debug|Any CPU = Debug|Any CPU
23+
Release|Any CPU = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
26+
{DB6CCC3F-D197-48F7-B166-E9194233939D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{DB6CCC3F-D197-48F7-B166-E9194233939D}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{DB6CCC3F-D197-48F7-B166-E9194233939D}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{DB6CCC3F-D197-48F7-B166-E9194233939D}.Release|Any CPU.Build.0 = Release|Any CPU
30+
{394AEA19-BF98-4427-BE95-BBD90A7D65A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31+
{394AEA19-BF98-4427-BE95-BBD90A7D65A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
32+
{394AEA19-BF98-4427-BE95-BBD90A7D65A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
33+
{394AEA19-BF98-4427-BE95-BBD90A7D65A5}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{56E79762-6BB4-4042-9EAB-2D819C2FDAB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35+
{56E79762-6BB4-4042-9EAB-2D819C2FDAB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{56E79762-6BB4-4042-9EAB-2D819C2FDAB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{56E79762-6BB4-4042-9EAB-2D819C2FDAB0}.Release|Any CPU.Build.0 = Release|Any CPU
38+
EndGlobalSection
39+
GlobalSection(SolutionProperties) = preSolution
40+
HideSolutionNode = FALSE
41+
EndGlobalSection
42+
EndGlobal

0 commit comments

Comments
 (0)