Skip to content

Commit 00e12ad

Browse files
committed
Main first commit of code
1 parent a7270c3 commit 00e12ad

31 files changed

+2131
-2
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

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,3 @@ nunit-*.xml
6161

6262
# Visual Studio
6363
.vs/
64-
/LocalGeneratorPackages/
65-
/pack_log.txt

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)