forked from DerivcoIpswich/dsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSharpAnalyzer.cs
More file actions
52 lines (44 loc) · 2.02 KB
/
Copy pathDSharpAnalyzer.cs
File metadata and controls
52 lines (44 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.Collections.Immutable;
using System.Diagnostics;
using DSharp.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
namespace DSharp.CodeAnalysis
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class DSharpAnalyzer : DiagnosticAnalyzer
{
private readonly DiagnosticDescriptor[] rules;
public DSharpAnalyzer()
{
this.rules = AvailableDiagnostics.Rules;
}
public DSharpAnalyzer(params DiagnosticDescriptor[] rules)
{
this.rules = rules;
if(rules.Length == 0)
this.rules = AvailableDiagnostics.Rules;
}
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
=> ImmutableArray.Create(rules);
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterCodeBlockAction(AnalyzeCodeBlock);
context.RegisterSymbolAction(AnalyzeMethodSymbol, SymbolKind.Method);
}
//TODO: Look at cleaning this up and making it easier to register processors and fixers etc.
private void AnalyzeCodeBlock(CodeBlockAnalysisContext context)
{
if(this.SupportedDiagnostics.Contains(AvailableDiagnostics.GenericTypeArgumentMissing.Rule))
AvailableDiagnostics.GenericTypeArgumentMissing.Analyzer.ProcessCodeBlock(context);
}
//TODO: Look at cleaning this up and making it easier to register processors and fixers etc.
private void AnalyzeMethodSymbol(SymbolAnalysisContext context)
{
if (this.SupportedDiagnostics.Contains(AvailableDiagnostics.ScriptIgnoreGenericArgumentsAttributeMissing.Rule))
AvailableDiagnostics.ScriptIgnoreGenericArgumentsAttributeMissing.Analyzer.ProcessSymbol(context);
}
}
}