Skip to content

Commit

Permalink
Group refactoring 'Remove members above/below' (#1308)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt committed Dec 2, 2023
1 parent 5886494 commit b785592
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Remove trailing dot from analyzer's title ([PR](https://github.com/dotnet/roslynator/pull/1298))
- Group code fix "Change accessibility to ..." ([PR](https://github.com/dotnet/roslynator/pull/1305))
- [CLI] Bump Roslyn to 4.8.0 ([PR](https://github.com/dotnet/roslynator/pull/1307)).
- Group refactoring "Remove members above/below'" ([PR](https://github.com/dotnet/roslynator/pull/1308))

### Fixed

Expand Down
@@ -1,10 +1,12 @@
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using Roslynator.CSharp.Syntax;
Expand Down Expand Up @@ -45,17 +47,21 @@ public static void ComputeRefactoring(RefactoringContext context, MemberDeclarat

if (context.IsRefactoringEnabled(RefactoringDescriptors.RemoveMemberDeclarations))
{
context.RegisterRefactoring(
"Remove members above",
ct => ReplaceMembersAsync(context.Document, info, members.Skip(index + 1), ct),
RefactoringDescriptors.RemoveMemberDeclarations,
"Above");
ImmutableArray<CodeAction> codeActions = ImmutableArray.Create(
CodeActionFactory.Create(
"above",
ct => ReplaceMembersAsync(context.Document, info, members.Skip(index + 1), ct),
RefactoringDescriptors.RemoveMemberDeclarations,
"Above"),
CodeActionFactory.Create(
"below",
ct => ReplaceMembersAsync(context.Document, info, members.Take(index + 1), ct),
RefactoringDescriptors.RemoveMemberDeclarations,
"Below"));

context.RegisterRefactoring(
"Remove members below",
ct => ReplaceMembersAsync(context.Document, info, members.Take(index + 1), ct),
RefactoringDescriptors.RemoveMemberDeclarations,
"Below");
"Remove members",
codeActions);
}

if (context.IsRefactoringEnabled(RefactoringDescriptors.SwapMemberDeclarations))
Expand Down

0 comments on commit b785592

Please sign in to comment.