Skip to content

new feature to move methods and fields between types#2498

Draft
amanthatdoescares wants to merge 1 commit intoswiftlang:mainfrom
amanthatdoescares:refactor-move-codeaction
Draft

new feature to move methods and fields between types#2498
amanthatdoescares wants to merge 1 commit intoswiftlang:mainfrom
amanthatdoescares:refactor-move-codeaction

Conversation

@amanthatdoescares
Copy link
Copy Markdown

@amanthatdoescares amanthatdoescares commented Feb 25, 2026

Add Move Member Refactoring Code Action (refactor.move)

This PR introduces a new Move Member Code Action to Swift LSP that allows users to move a member declaration (e.g. property, method, enum case) from one type to another.

The action is surfaced under the Refactor… menu when the cursor is placed inside a member of a nominal type (struct, class, or enum). It is not offered for top-level declarations.

The implementation adds a new provider in:

Sources/SwiftLanguageService/CodeActions/MoveMember.swift

which detects MemberBlockItemSyntax at the cursor position and returns a command-based Code Action (swift.moveMember) of kind "refactor.move".

Tests Added

Added test coverage in:

Tests/SourceKitLSPTests/CodeActionTests.swift

  • testMoveMemberCodeAction
  • testMoveMemberCodeActionNotOfferedForTopLevelCode

feature: #2384

Copy link
Copy Markdown
Contributor

@plemarquand plemarquand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What client implements the swift.moveMember command? How do you choose what type to move the method/field to?

@amanthatdoescares amanthatdoescares marked this pull request as draft February 25, 2026 15:46
@amanthatdoescares
Copy link
Copy Markdown
Author

What client implements the swift.moveMember command? How do you choose what type to move the method/field to?

Thanks for raising this. At the moment, the PR only adds the server-side code action and command, and the client interaction needed to select the destination type is not implemented yet.

I’ll complete the expected LSP flow by adding support to query valid destination types, allowing the client to prompt the user, and then execute swift.moveMember with the selected target. I’ll put this up for review again once the full interaction is implemented end-to-end.

@plemarquand
Copy link
Copy Markdown
Contributor

What does the list of destination types look like? Is it only ones in the same file? same module? entire project? How do you avoid overwhelming the user with potentially 100s of options? What is the UX in the client for picking a destination type?

@amanthatdoescares
Copy link
Copy Markdown
Author

What does the list of destination types look like? Is it only ones in the same file? same module? entire project? How do you avoid overwhelming the user with potentially 100s of options? What is the UX in the client for picking a destination type?

That makes sense. I’ll take this into account while revisiting the design and will avoid a broad project-wide destination list.

Before finalizing the approach, I plan to start a discussion on the Swift forums outlining the proposed behavior (limiting destinations to structurally valid containers in the immediate lexical hierarchy) to gather feedback and ensure alignment on the intended UX and scope.

I’ll proceed with implementation once there’s clarity and consensus around the direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants