-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c0434c
commit 47c9945
Showing
6 changed files
with
102 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using System; | ||
|
||
namespace Decuplr.Sourceberg.Generator { | ||
public class Class1 { | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/Decuplr.Sourceberg.Generator/Decuplr.Sourceberg.Generator.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using Decuplr.Sourceberg.Generation; | ||
using Decuplr.Sourceberg.Services; | ||
using Decuplr.Sourceberg.Services.Implementation; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Decuplr.Sourceberg.Internal { | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public abstract class SourcebergBase { | ||
|
||
private readonly ServiceCollection _services = new ServiceCollection(); | ||
|
||
private protected IReadOnlyList<AnalyzerGroupInfo<ISymbol, SymbolAnalysisContextSource, SymbolKind>> SymbolActionGroups { get; } | ||
private protected IReadOnlyList<AnalyzerGroupInfo<SyntaxNode, SyntaxNodeAnalysisContextSource, SyntaxKind>> SyntaxActionGroups { get; } | ||
|
||
private protected SourcebergBase(GeneratorStartup startup) { | ||
var syntaxActionSetup = new SyntaxAnalyzerSetup(); | ||
var symbolActionSetup = new SymbolAnalyzerGroupSetup(); | ||
startup.ConfigureAnalyzer(new AnalyzerSetupContext(syntaxActionSetup, symbolActionSetup)); | ||
startup.ConfigureServices(_services); | ||
SyntaxActionGroups = syntaxActionSetup.AnalyzerGroups; | ||
SymbolActionGroups = symbolActionSetup.AnalyzerGroups; | ||
|
||
foreach (var (actionGroup, _) in SyntaxActionGroups) { | ||
actionGroup.RegisterServices(_services); | ||
} | ||
foreach (var (actionGroup, _) in SymbolActionGroups) { | ||
actionGroup.RegisterServices(_services); | ||
} | ||
|
||
// Add default services | ||
_services.AddScopedGroup<SourceContextAccessor, IAnalysisLifetime>(); | ||
_services.AddScopedGroup<TypeSymbolProvider, ITypeSymbolProvider, ISourceAddition>(); | ||
|
||
_services.AddScopedGroup<AttributeLayoutProvider, IAttributeLayoutProvider>(); | ||
_services.AddScopedGroup<ContextCollectionProvider, IContextCollectionProvider>(); | ||
_services.AddScoped<TypeSymbolLocatorCache>(); | ||
} | ||
|
||
protected IServiceProvider CreateServiceProvider() => _services.BuildServiceProvider(); | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/Decuplr.Sourceberg/Internal/SourcebergSyntaxReceiver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using Decuplr.Sourceberg.Generation; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Decuplr.Sourceberg.Internal { | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public sealed class SourcebergSyntaxReceiver : ISyntaxReceiver { | ||
private readonly List<SyntaxNode> _nodes = new List<SyntaxNode>(); | ||
|
||
internal IReadOnlyList<SyntaxNode> CapturedNodes => _nodes; | ||
internal GeneratorStartup Startup { get; } | ||
|
||
internal SourcebergSyntaxReceiver(GeneratorStartup startup) => Startup = startup; | ||
|
||
public void OnVisitSyntaxNode(SyntaxNode syntaxNode) { | ||
if (Startup.ShouldCapture(syntaxNode)) | ||
_nodes.Add(syntaxNode); | ||
} | ||
} | ||
|
||
} |