Skip to content

Commit

Permalink
Fix conflict between fixers that was preventing one from showing up.
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Aug 23, 2018
1 parent 5517c98 commit 856932a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@ internal class CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider : S
public override ImmutableArray<string> FixableDiagnosticIds
=> ImmutableArray.Create(IDEDiagnosticIds.UseIsNullCheckDiagnosticId);

private static bool IsSupportedDiagnostic(Diagnostic diagnostic)
=> diagnostic.Properties[UseIsNullConstants.Kind] == UseIsNullConstants.CastAndEqualityKey;

public override Task RegisterCodeFixesAsync(CodeFixContext context)
{
var diagnostic = context.Diagnostics.First();
if (IsSupportedDiagnostic(diagnostic))
{
context.RegisterCodeFix(
new MyCodeAction(CSharpFeaturesResources.Use_is_null_check,
c => this.FixAsync(context.Document, diagnostic, c)),
context.Diagnostics);
}

context.RegisterCodeFix(
new MyCodeAction(CSharpFeaturesResources.Use_is_null_check,
c => this.FixAsync(context.Document, diagnostic, c)),
context.Diagnostics);
return Task.CompletedTask;
}

Expand All @@ -42,7 +48,7 @@ protected override Task FixAllAsync(
{
foreach (var diagnostic in diagnostics)
{
if (diagnostic.Properties[UseIsNullConstants.Kind] != UseIsNullConstants.CastAndEqualityKey)
if (!IsSupportedDiagnostic(diagnostic))
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@ public override ImmutableArray<string> FixableDiagnosticIds
protected abstract SyntaxNode CreateNullCheck(SyntaxNode argument, bool isUnconstrainedGeneric);
protected abstract SyntaxNode CreateNotNullCheck(SyntaxNode notExpression, SyntaxNode argument, bool isUnconstrainedGeneric);

private static bool IsSupportedDiagnostic(Diagnostic diagnostic)
=> diagnostic.Properties[UseIsNullConstants.Kind] == UseIsNullConstants.ReferenceEqualsKey;

public override Task RegisterCodeFixesAsync(CodeFixContext context)
{
var diagnostic = context.Diagnostics.First();
var negated = diagnostic.Properties.ContainsKey(Negated);
var title = negated ? GetIsNotNullTitle() : GetIsNullTitle();
if (IsSupportedDiagnostic(diagnostic))
{
var negated = diagnostic.Properties.ContainsKey(Negated);
var title = negated ? GetIsNotNullTitle() : GetIsNullTitle();

context.RegisterCodeFix(
new MyCodeAction(title, c => this.FixAsync(context.Document, diagnostic, c)),
context.Diagnostics);
}

context.RegisterCodeFix(
new MyCodeAction(title, c => this.FixAsync(context.Document, diagnostic, c)),
context.Diagnostics);
return Task.CompletedTask;
}

Expand All @@ -51,7 +58,7 @@ protected override Task FixAllAsync(
// not there once their parent has been replaced.
foreach (var diagnostic in diagnostics.OrderByDescending(d => d.Location.SourceSpan.Start))
{
if (diagnostic.Properties[UseIsNullConstants.Kind] != UseIsNullConstants.ReferenceEqualsKey)
if (!IsSupportedDiagnostic(diagnostic))
{
continue;
}
Expand Down

0 comments on commit 856932a

Please sign in to comment.