Skip to content

Commit

Permalink
Update code fix title
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored and JochemHarmes committed Oct 30, 2023
1 parent fb94902 commit 91034cf
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -259,7 +260,7 @@ public static void RemoveModifiers(
else
{
CodeAction codeAction = CodeAction.Create(
"Remove modifiers",
GetRemoveModifiersTitle(modifiers, predicate),
ct =>
{
SyntaxNode newNode = node;
Expand All @@ -282,16 +283,17 @@ public static void RemoveModifiers(
SyntaxNode node,
string additionalKey = null)
{
SyntaxToken modifier = SyntaxInfo.ModifierListInfo(node).Modifiers.SingleOrDefault(shouldThrow: false);
SyntaxTokenList modifiers = SyntaxInfo.ModifierListInfo(node).Modifiers;
SyntaxToken modifier = modifiers.SingleOrDefault(shouldThrow: false);

if (modifier != default)
if (!modifier.IsKind(SyntaxKind.None))
{
RemoveModifier(context, diagnostic, node, modifier, additionalKey);
}
else
{
CodeAction codeAction = CodeAction.Create(
"Remove modifiers",
GetRemoveModifiersTitle(modifiers),
ct =>
{
SyntaxNode newNode = ModifierList.RemoveAll(node);
Expand Down Expand Up @@ -431,6 +433,18 @@ private static string GetAddModifierTitle(SyntaxKind modifierKind, SyntaxNode no

internal static string GetRemoveModifierTitle(SyntaxKind modifierKind)
{
return $"Remove modifier '{GetText(modifierKind)}'";
return (IsAccessibilityModifier(modifierKind))
? "Remove access modifier"
: $"Remove modifier '{GetText(modifierKind)}'";
}

private static string GetRemoveModifiersTitle(IEnumerable<SyntaxToken> modifiers, Func<SyntaxToken, bool> predicate = null)
{
if (predicate is not null)
modifiers = modifiers.Where(predicate);

return (modifiers.All(m => IsAccessibilityModifier(m.Kind())))
? "Remove access modifiers"
: "Remove modifiers";
}
}

0 comments on commit 91034cf

Please sign in to comment.