-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
7 changed files
with
449 additions
and
9 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/TelescopeSourceGenerator/Analyzers/Diagnostics/TesDiagnostics.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,79 @@ | ||
using Microsoft.CodeAnalysis; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Resources; | ||
using System.Text; | ||
using dotnetCampus.Telescope.SourceGeneratorAnalyzers.Properties; | ||
using static dotnetCampus.Telescope.SourceGeneratorAnalyzers.Properties.Resources; | ||
|
||
using static Microsoft.CodeAnalysis.WellKnownDiagnosticTags; | ||
|
||
namespace dotnetCampus.Telescope.SourceGeneratorAnalyzers.Diagnostics; | ||
|
||
static class TesDiagnostics | ||
{ | ||
// ReSharper disable InconsistentNaming | ||
public static DiagnosticDescriptor Tes000_UnknownError => new DiagnosticDescriptor | ||
( | ||
nameof(Tes000), | ||
Localize(nameof(Tes000)), | ||
Localize(nameof(Tes000_Message)), | ||
Categories.Compiler, | ||
DiagnosticSeverity.Error, | ||
true, | ||
customTags: new[] { AnalyzerException, NotConfigurable } | ||
); | ||
|
||
public static DiagnosticDescriptor Tes001_MethodReturnTypeError => new DiagnosticDescriptor | ||
( | ||
nameof(Tes001), | ||
Localize(nameof(Tes001)), | ||
Localize(nameof(Tes001_Message)), | ||
Categories.Compiler, | ||
DiagnosticSeverity.Error, | ||
true, | ||
customTags: new[] { AnalyzerException, NotConfigurable } | ||
); | ||
|
||
|
||
private static class Categories | ||
{ | ||
/// <summary> | ||
/// 可能产生 bug,则报告此诊断。 | ||
/// </summary> | ||
public const string AvoidBugs = "dotnetCampus.AvoidBugs"; | ||
|
||
/// <summary> | ||
/// 为了提供代码生成能力,则报告此诊断。 | ||
/// </summary> | ||
public const string CodeFixOnly = "dotnetCampus.CodeFixOnly"; | ||
|
||
/// <summary> | ||
/// 因编译要求而必须满足的条件没有满足,则报告此诊断。 | ||
/// </summary> | ||
public const string Compiler = "dotnetCampus.Compiler"; | ||
|
||
/// <summary> | ||
/// 因 Telescope 库内的机制限制,必须满足此要求 Telescope 才可正常工作,则报告此诊断。 | ||
/// </summary> | ||
public const string Mechanism = "dotnetCampus.Mechanism"; | ||
|
||
/// <summary> | ||
/// 为了代码可读性,使之更易于理解、方便调试,则报告此诊断。 | ||
/// </summary> | ||
public const string Readable = "dotnetCampus.Readable"; | ||
|
||
/// <summary> | ||
/// 能写得出来正常编译,但会引发运行时异常,则报告此诊断。 | ||
/// </summary> | ||
public const string RuntimeException = "dotnetCampus.RuntimeException"; | ||
|
||
/// <summary> | ||
/// 编写了无法生效的代码,则报告此诊断。 | ||
/// </summary> | ||
public const string Useless = "dotnetCampus.Useless"; | ||
} | ||
|
||
private static LocalizableString Localize(string key) => new LocalizableResourceString(key, dotnetCampus.Telescope.SourceGeneratorAnalyzers.Properties.Resources.ResourceManager, typeof(Resources)); | ||
} |
17 changes: 16 additions & 1 deletion
17
...urceGenerator/Analyzers/ExportTypeToMethod_/ExportMethodReturnTypeCollectionDiagnostic.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 |
---|---|---|
@@ -1,5 +1,20 @@ | ||
namespace dotnetCampus.Telescope.SourceGeneratorAnalyzers; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace dotnetCampus.Telescope.SourceGeneratorAnalyzers; | ||
|
||
class ExportMethodReturnTypeCollectionDiagnostic : IExportMethodReturnTypeCollectionResult | ||
{ | ||
public ExportMethodReturnTypeCollectionDiagnostic(DiagnosticDescriptor diagnosticDescriptor, | ||
Location? location = null, params object[]? messageArgs) | ||
{ | ||
DiagnosticDescriptor = diagnosticDescriptor; | ||
Location = location; | ||
MessageArgs = messageArgs; | ||
} | ||
|
||
public Location? Location { get; set; } | ||
public DiagnosticDescriptor DiagnosticDescriptor { get; } | ||
public object[]? MessageArgs { set; get; } | ||
|
||
public Diagnostic ToDiagnostic() => Diagnostic.Create(DiagnosticDescriptor, Location, MessageArgs); | ||
} |
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
63 changes: 63 additions & 0 deletions
63
src/TelescopeSourceGenerator/Analyzers/Properties/Resource.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
src/TelescopeSourceGenerator/Analyzers/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.