未验证 提交 850f809c 编写于 作者: J Julien Couvreur 提交者: GitHub

Only the compiler analyzer can use CS or BC prefix for diagnostics (#23776)

上级 49ada5d9
......@@ -888,6 +888,36 @@ public void TestReportingDiagnosticWithInvalidId()
.WithLocation(1, 1));
}
[Fact, WorkItem(23667, "https://github.com/dotnet/roslyn/issues/23667")]
public void TestReportingDiagnosticWithCSharpCompilerId()
{
string source = @"";
var analyzers = new DiagnosticAnalyzer[] { new AnalyzerWithCSharpCompilerDiagnosticId() };
string message = new ArgumentException(string.Format(CodeAnalysisResources.CompilerDiagnosticIdReported, AnalyzerWithCSharpCompilerDiagnosticId.Descriptor.Id), "diagnostic").Message;
CreateCompilationWithMscorlib45(source)
.VerifyDiagnostics()
.VerifyAnalyzerDiagnostics(analyzers, null, null, logAnalyzerExceptionAsDiagnostics: true,
expected: Diagnostic("AD0001")
.WithArguments("Microsoft.CodeAnalysis.CommonDiagnosticAnalyzers+AnalyzerWithCSharpCompilerDiagnosticId", "System.ArgumentException", message)
.WithLocation(1, 1));
}
[Fact, WorkItem(23667, "https://github.com/dotnet/roslyn/issues/23667")]
public void TestReportingDiagnosticWithBasicCompilerId()
{
string source = @"";
var analyzers = new DiagnosticAnalyzer[] { new AnalyzerWithBasicCompilerDiagnosticId() };
string message = new ArgumentException(string.Format(CodeAnalysisResources.CompilerDiagnosticIdReported, AnalyzerWithBasicCompilerDiagnosticId.Descriptor.Id), "diagnostic").Message;
CreateCompilationWithMscorlib45(source)
.VerifyDiagnostics()
.VerifyAnalyzerDiagnostics(analyzers, null, null, logAnalyzerExceptionAsDiagnostics: true,
expected: Diagnostic("AD0001")
.WithArguments("Microsoft.CodeAnalysis.CommonDiagnosticAnalyzers+AnalyzerWithBasicCompilerDiagnosticId", "System.ArgumentException", message)
.WithLocation(1, 1));
}
[Fact, WorkItem(7173, "https://github.com/dotnet/roslyn/issues/7173")]
public void TestReportingDiagnosticWithInvalidLocation()
{
......
......@@ -405,6 +405,15 @@ internal class CodeAnalysisResources {
}
}
/// <summary>
/// Looks up a localized string similar to Reported diagnostic has an ID &apos;{0}&apos;, which only a compiler should be reporting..
/// </summary>
internal static string CompilerDiagnosticIdReported {
get {
return ResourceManager.GetString("CompilerDiagnosticIdReported", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to constructor.
/// </summary>
......
......@@ -446,6 +446,9 @@
<data name="InvalidDiagnosticIdReported" xml:space="preserve">
<value>Reported diagnostic has an ID '{0}', which is not a valid identifier.</value>
</data>
<data name="CompilerDiagnosticIdReported" xml:space="preserve">
<value>Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</value>
</data>
<data name="InvalidDiagnosticLocationReported" xml:space="preserve">
<value>Reported diagnostic '{0}' has a source location in file '{1}', which is not part of the compilation being analyzed.</value>
</data>
......
......@@ -168,6 +168,11 @@ internal bool IsSupportedDiagnostic(DiagnosticAnalyzer analyzer, Diagnostic diag
return true;
}
if (IsCompilerReservedDiagnostic(diagnostic.Id))
{
throw new ArgumentException(string.Format(CodeAnalysisResources.CompilerDiagnosticIdReported, diagnostic.Id), nameof(diagnostic));
}
// Get all the supported diagnostics and scan them linearly to see if the reported diagnostic is supported by the analyzer.
// The linear scan is okay, given that this runs only if a diagnostic is being reported and a given analyzer is quite unlikely to have hundreds of thousands of supported diagnostics.
var supportedDescriptors = GetSupportedDiagnosticDescriptors(analyzer, analyzerExecutor);
......@@ -182,6 +187,18 @@ internal bool IsSupportedDiagnostic(DiagnosticAnalyzer analyzer, Diagnostic diag
return false;
}
private static bool IsCompilerReservedDiagnostic(string id)
{
// Only the compiler analyzer should produce diagnostics with CS or BC prefixes (followed by digit)
if (id.Length >= 3 && (id.StartsWith("CS", StringComparison.Ordinal) || id.StartsWith("BC", StringComparison.Ordinal)))
{
char thirdChar = id[2];
return thirdChar >= '0' && thirdChar <= '9';
}
return false;
}
/// <summary>
/// Returns true if all the diagnostics that can be produced by this analyzer are suppressed through options.
/// </summary>
......
......@@ -828,6 +828,11 @@
<target state="new">Warning: Could not enable multicore JIT due to exception: {0}.</target>
<note />
</trans-unit>
<trans-unit id="CompilerDiagnosticIdReported">
<source>Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</source>
<target state="new">Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -828,6 +828,11 @@
<target state="new">Warning: Could not enable multicore JIT due to exception: {0}.</target>
<note />
</trans-unit>
<trans-unit id="CompilerDiagnosticIdReported">
<source>Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</source>
<target state="new">Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -828,6 +828,11 @@
<target state="new">Warning: Could not enable multicore JIT due to exception: {0}.</target>
<note />
</trans-unit>
<trans-unit id="CompilerDiagnosticIdReported">
<source>Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</source>
<target state="new">Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -828,6 +828,11 @@
<target state="new">Warning: Could not enable multicore JIT due to exception: {0}.</target>
<note />
</trans-unit>
<trans-unit id="CompilerDiagnosticIdReported">
<source>Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</source>
<target state="new">Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -828,6 +828,11 @@
<target state="new">Warning: Could not enable multicore JIT due to exception: {0}.</target>
<note />
</trans-unit>
<trans-unit id="CompilerDiagnosticIdReported">
<source>Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</source>
<target state="new">Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -828,6 +828,11 @@
<target state="new">Warning: Could not enable multicore JIT due to exception: {0}.</target>
<note />
</trans-unit>
<trans-unit id="CompilerDiagnosticIdReported">
<source>Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</source>
<target state="new">Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -828,6 +828,11 @@
<target state="new">Warning: Could not enable multicore JIT due to exception: {0}.</target>
<note />
</trans-unit>
<trans-unit id="CompilerDiagnosticIdReported">
<source>Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</source>
<target state="new">Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -828,6 +828,11 @@
<target state="new">Warning: Could not enable multicore JIT due to exception: {0}.</target>
<note />
</trans-unit>
<trans-unit id="CompilerDiagnosticIdReported">
<source>Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</source>
<target state="new">Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -828,6 +828,11 @@
<target state="new">Warning: Could not enable multicore JIT due to exception: {0}.</target>
<note />
</trans-unit>
<trans-unit id="CompilerDiagnosticIdReported">
<source>Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</source>
<target state="new">Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -828,6 +828,11 @@
<target state="new">Warning: Could not enable multicore JIT due to exception: {0}.</target>
<note />
</trans-unit>
<trans-unit id="CompilerDiagnosticIdReported">
<source>Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</source>
<target state="new">Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -828,6 +828,11 @@
<target state="new">Warning: Could not enable multicore JIT due to exception: {0}.</target>
<note />
</trans-unit>
<trans-unit id="CompilerDiagnosticIdReported">
<source>Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</source>
<target state="new">Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -828,6 +828,11 @@
<target state="new">Warning: Could not enable multicore JIT due to exception: {0}.</target>
<note />
</trans-unit>
<trans-unit id="CompilerDiagnosticIdReported">
<source>Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</source>
<target state="new">Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -828,6 +828,11 @@
<target state="new">Warning: Could not enable multicore JIT due to exception: {0}.</target>
<note />
</trans-unit>
<trans-unit id="CompilerDiagnosticIdReported">
<source>Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</source>
<target state="new">Reported diagnostic has an ID '{0}', which only a compiler should be reporting.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -4,6 +4,7 @@
using System.Composition;
using Microsoft.CodeAnalysis.AddImport;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Packaging;
using Microsoft.CodeAnalysis.SymbolSearch;
......@@ -122,7 +123,8 @@ internal static class AddImportDiagnosticIds
CS0616,
CS1580,
CS1581,
CS8129);
CS8129,
IDEDiagnosticIds.UnboundIdentifierId);
public static ImmutableArray<string> FixableDiagnosticIds =
FixableTypeIds.Concat(ImmutableArray.Create(
......
......@@ -12,6 +12,7 @@
using Microsoft.CodeAnalysis.CSharp.Extensions;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServices;
......@@ -153,6 +154,7 @@ protected override bool CanAddImportForType(string diagnosticId, SyntaxNode node
switch (diagnosticId)
{
case CS0103:
case IDEDiagnosticIds.UnboundIdentifierId:
case CS0246:
case CS0305:
case CS0308:
......
......@@ -9,6 +9,7 @@
using Microsoft.CodeAnalysis.CodeFixes.GenerateMember;
using Microsoft.CodeAnalysis.CSharp.Extensions;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.GenerateType;
using Microsoft.CodeAnalysis.Shared.Extensions;
......@@ -29,7 +30,7 @@ internal class GenerateTypeCodeFixProvider : AbstractGenerateMemberCodeFixProvid
public override ImmutableArray<string> FixableDiagnosticIds
{
get { return ImmutableArray.Create(CS0103, CS0117, CS0234, CS0246, CS0305, CS0308, CS0426, CS0616); }
get { return ImmutableArray.Create(CS0103, CS0117, CS0234, CS0246, CS0305, CS0308, CS0426, CS0616, IDEDiagnosticIds.UnboundIdentifierId); }
}
protected override bool IsCandidate(SyntaxNode node, SyntaxToken token, Diagnostic diagnostic)
......
......@@ -10,19 +10,19 @@ namespace Microsoft.CodeAnalysis.CSharp.Diagnostics
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal sealed class CSharpUnboundIdentifiersDiagnosticAnalyzer : UnboundIdentifiersDiagnosticAnalyzerBase<SyntaxKind, SimpleNameSyntax, QualifiedNameSyntax, IncompleteMemberSyntax, LambdaExpressionSyntax>
{
private const string NameNotInContext = "CS0103";
private readonly LocalizableString _nameNotInContextMessageFormat = new LocalizableResourceString(nameof(CSharpFeaturesResources.The_name_0_does_not_exist_in_the_current_context), CSharpFeaturesResources.ResourceManager, typeof(CSharpFeaturesResources));
private readonly LocalizableString _nameNotInContextMessageFormat =
new LocalizableResourceString(nameof(CSharpFeaturesResources.The_name_0_does_not_exist_in_the_current_context), CSharpFeaturesResources.ResourceManager, typeof(CSharpFeaturesResources));
private const string ConstructorOverloadResolutionFailure = "CS1729";
private readonly LocalizableString _constructorOverloadResolutionFailureMessageFormat = new LocalizableResourceString(nameof(CSharpFeaturesResources._0_does_not_contain_a_constructor_that_takes_that_many_arguments), CSharpFeaturesResources.ResourceManager, typeof(CSharpFeaturesResources));
private readonly LocalizableString _constructorOverloadResolutionFailureMessageFormat =
new LocalizableResourceString(nameof(CSharpFeaturesResources._0_does_not_contain_a_constructor_that_takes_that_many_arguments), CSharpFeaturesResources.ResourceManager, typeof(CSharpFeaturesResources));
private static readonly ImmutableArray<SyntaxKind> s_kindsOfInterest = ImmutableArray.Create(SyntaxKind.IncompleteMember, SyntaxKind.ParenthesizedLambdaExpression, SyntaxKind.SimpleLambdaExpression);
protected override ImmutableArray<SyntaxKind> SyntaxKindsOfInterest => s_kindsOfInterest;
protected override DiagnosticDescriptor DiagnosticDescriptor => GetDiagnosticDescriptor(NameNotInContext, _nameNotInContextMessageFormat);
protected override DiagnosticDescriptor DiagnosticDescriptor => GetDiagnosticDescriptor(IDEDiagnosticIds.UnboundIdentifierId, _nameNotInContextMessageFormat);
protected override DiagnosticDescriptor DiagnosticDescriptor2 => GetDiagnosticDescriptor(ConstructorOverloadResolutionFailure, _constructorOverloadResolutionFailureMessageFormat);
protected override DiagnosticDescriptor DiagnosticDescriptor2 => GetDiagnosticDescriptor(IDEDiagnosticIds.UnboundConstructorId, _constructorOverloadResolutionFailureMessageFormat);
protected override bool ConstructorDoesNotExist(SyntaxNode node, SymbolInfo info, SemanticModel model)
{
......
......@@ -9,6 +9,7 @@
using Microsoft.CodeAnalysis.CodeFixes.GenerateMember;
using Microsoft.CodeAnalysis.CSharp.Extensions;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.GenerateMember.GenerateConstructor;
using Microsoft.CodeAnalysis.Shared.Extensions;
......@@ -23,7 +24,7 @@ internal static class GenerateConstructorDiagnosticIds
public const string CS7036 = nameof(CS7036); // CS7036: There is no argument given that corresponds to the required formal parameter 'v' of 'C.C(int)'
public static readonly ImmutableArray<string> AllDiagnosticIds =
ImmutableArray.Create(CS0122, CS1729, CS1739, CS1503, CS7036);
ImmutableArray.Create(CS0122, CS1729, CS1739, CS1503, CS7036, IDEDiagnosticIds.UnboundConstructorId);
public static readonly ImmutableArray<string> TooManyArgumentsDiagnosticIds =
ImmutableArray.Create(CS1729);
......
......@@ -70,5 +70,7 @@ internal static class IDEDiagnosticIds
public const string ErrorReadingRulesetId = "IDE1004";
public const string InvokeDelegateWithConditionalAccessId = "IDE1005";
public const string NamingRuleId = "IDE1006";
public const string UnboundIdentifierId = "IDE1007";
public const string UnboundConstructorId = "IDE1008";
}
}
......@@ -4,6 +4,7 @@ Imports System.Collections.Immutable
Imports System.Composition
Imports Microsoft.CodeAnalysis.AddImport
Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.Packaging
Imports Microsoft.CodeAnalysis.SymbolSearch
......@@ -100,7 +101,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.AddImport
Public Overrides ReadOnly Property FixableDiagnosticIds As ImmutableArray(Of String)
Get
Return ImmutableArray.Create(BC30002, BC30451, BC30456, BC32042, BC36593, BC32045, BC30389, BC31504, BC32016, BC36610, BC36719, BC30512, BC30390, BC42309, BC30182)
Return ImmutableArray.Create(BC30002, BC30451, BC30456, BC32042, BC36593, BC32045, BC30389, BC31504, BC32016, BC36610,
BC36719, BC30512, BC30390, BC42309, BC30182, IDEDiagnosticIds.UnboundIdentifierId)
End Get
End Property
End Class
......
......@@ -5,6 +5,7 @@ Imports System.Threading
Imports Microsoft.CodeAnalysis.AddImport
Imports Microsoft.CodeAnalysis.AddImports
Imports Microsoft.CodeAnalysis.CaseCorrection
Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.Formatting
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.LanguageServices
......@@ -88,6 +89,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.AddImport
Protected Overrides Function CanAddImportForNamespace(diagnosticId As String, node As SyntaxNode, ByRef nameNode As SimpleNameSyntax) As Boolean
Select Case diagnosticId
Case VisualBasicAddImportCodeFixProvider.BC30002,
IDEDiagnosticIds.UnboundIdentifierId,
VisualBasicAddImportCodeFixProvider.BC30451
Exit Select
Case Else
......@@ -120,6 +122,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.AddImport
diagnosticId As String, node As SyntaxNode, ByRef nameNode As SimpleNameSyntax) As Boolean
Select Case diagnosticId
Case VisualBasicAddImportCodeFixProvider.BC30002,
IDEDiagnosticIds.UnboundIdentifierId,
VisualBasicAddImportCodeFixProvider.BC30451,
VisualBasicAddImportCodeFixProvider.BC32042,
VisualBasicAddImportCodeFixProvider.BC32045,
......
......@@ -6,6 +6,7 @@ Imports System.Threading
Imports Microsoft.CodeAnalysis.CodeActions
Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.CodeFixes.GenerateMember
Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.GenerateType
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -26,7 +27,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateType
Public Overrides ReadOnly Property FixableDiagnosticIds As ImmutableArray(Of String)
Get
Return ImmutableArray.Create(BC30002, BC30182, BC30451, BC30456, BC32042, BC32043, BC32045, BC40056)
Return ImmutableArray.Create(BC30002, IDEDiagnosticIds.UnboundIdentifierId, BC30182, BC30451, BC30456, BC32042, BC32043, BC32045, BC40056)
End Get
End Property
......
......@@ -4,6 +4,7 @@ Imports System.Collections.Immutable
Imports System.Composition
Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.Completion
Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.SpellCheck
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -36,7 +37,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.Spellcheck
Public NotOverridable Overrides ReadOnly Property FixableDiagnosticIds As ImmutableArray(Of String)
Get
Return ImmutableArray.Create(BC30002, BC30451, BC30456, BC32045)
Return ImmutableArray.Create(BC30002, IDEDiagnosticIds.UnboundIdentifierId, BC30451, BC30456, BC32045)
End Get
End Property
......
......@@ -10,9 +10,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Diagnostics
Friend NotInheritable Class VisualBasicUnboundIdentifiersDiagnosticAnalyzer
Inherits UnboundIdentifiersDiagnosticAnalyzerBase(Of SyntaxKind, SimpleNameSyntax, QualifiedNameSyntax, IncompleteMemberSyntax, LambdaExpressionSyntax)
Private Const s_undefinedType1 As String = "BC30002"
Private ReadOnly _messageFormat As LocalizableString = New LocalizableResourceString(NameOf(VBFeaturesResources.Type_0_is_not_defined), VBFeaturesResources.ResourceManager, GetType(VBFeaturesResources.VBFeaturesResources))
Private Const s_undefinedType2 As String = "BC30057"
Private ReadOnly _messageFormat2 As LocalizableString = New LocalizableResourceString(NameOf(VBFeaturesResources.Too_many_arguments_to_0), VBFeaturesResources.ResourceManager, GetType(VBFeaturesResources.VBFeaturesResources))
......@@ -31,13 +29,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Diagnostics
Protected Overrides ReadOnly Property DiagnosticDescriptor As DiagnosticDescriptor
Get
Return GetDiagnosticDescriptor(s_undefinedType1, _messageFormat)
Return GetDiagnosticDescriptor(IDEDiagnosticIds.UnboundIdentifierId, _messageFormat)
End Get
End Property
Protected Overrides ReadOnly Property DiagnosticDescriptor2 As DiagnosticDescriptor
Get
Return GetDiagnosticDescriptor(s_undefinedType2, _messageFormat2)
Return GetDiagnosticDescriptor(IDEDiagnosticIds.UnboundConstructorId, _messageFormat2)
End Get
End Property
......
......@@ -7,6 +7,7 @@ Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.CaseCorrection
Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.CodeFixes.FullyQualify
Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.Formatting
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -43,7 +44,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.FullyQualify
Public Overrides ReadOnly Property FixableDiagnosticIds As ImmutableArray(Of String)
Get
Return ImmutableArray.Create(BC30002, BC30451, BC30561, BC40056, BC32045)
Return ImmutableArray.Create(BC30002, IDEDiagnosticIds.UnboundIdentifierId, BC30451, BC30561, BC40056, BC32045)
End Get
End Property
......
......@@ -6,6 +6,7 @@ Imports System.Threading
Imports Microsoft.CodeAnalysis.CodeActions
Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.CodeFixes.GenerateMember
Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.GenerateMember.GenerateConstructor
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -21,8 +22,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateConstructor
Friend Const BC30387 As String = "BC30387" ' error BC32006: Class 'Derived' must declare a 'Sub New' because its base class 'Base' does not have an accessible 'Sub New' that can be called with no arguments.
Friend Const BC30516 As String = "BC30516" ' error BC30516: Overload resolution failed because no accessible 'Blah' accepts this number of arguments.
Friend Shared ReadOnly AllDiagnosticIds As ImmutableArray(Of String) = ImmutableArray.Create(BC30057, BC30272, BC30274, BC30389, BC30455, BC32006, BC30512, BC30387, BC30516)
Friend Shared ReadOnly TooManyArgumentsDiagnosticIds As ImmutableArray(Of String) = ImmutableArray.Create(BC30057)
Friend Shared ReadOnly AllDiagnosticIds As ImmutableArray(Of String) = ImmutableArray.Create(BC30057, IDEDiagnosticIds.UnboundConstructorId, BC30272, BC30274, BC30389, BC30455, BC32006, BC30512, BC30387, BC30516)
Friend Shared ReadOnly TooManyArgumentsDiagnosticIds As ImmutableArray(Of String) = ImmutableArray.Create(BC30057, IDEDiagnosticIds.UnboundConstructorId)
End Class
<ExportCodeFixProvider(LanguageNames.VisualBasic, Name:=PredefinedCodeFixProviderNames.GenerateConstructor), [Shared]>
......
......@@ -461,6 +461,44 @@ public override void Initialize(AnalysisContext context)
}
}
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
public sealed class AnalyzerWithCSharpCompilerDiagnosticId : DiagnosticAnalyzer
{
public static readonly DiagnosticDescriptor Descriptor = new DiagnosticDescriptor(
"CS101",
"Title1",
"Message1",
"Category1",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Descriptor);
public override void Initialize(AnalysisContext context)
{
context.RegisterCompilationAction(compilationContext =>
compilationContext.ReportDiagnostic(Diagnostic.Create(Descriptor, Location.None)));
}
}
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
public sealed class AnalyzerWithBasicCompilerDiagnosticId : DiagnosticAnalyzer
{
public static readonly DiagnosticDescriptor Descriptor = new DiagnosticDescriptor(
"BC101",
"Title1",
"Message1",
"Category1",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Descriptor);
public override void Initialize(AnalysisContext context)
{
context.RegisterCompilationAction(compilationContext =>
compilationContext.ReportDiagnostic(Diagnostic.Create(Descriptor, Location.None)));
}
}
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
public sealed class AnalyzerWithInvalidDiagnosticSpan : DiagnosticAnalyzer
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册