Skip to content

Conversation

@iMostfa
Copy link
Contributor

@iMostfa iMostfa commented Dec 21, 2025

Resolves: #2145
along with: swiftlang/swift#86173

example.mov

Add Copy Objective-C Selector code action

Implements a new refactor action that allows users to copy Objective-C
selectors from Swift code. Adds the objcSelector SourceKitD request and
corresponding command handling in the language service.

If the approach is okay, i can go forward with adding/updating tests, lint..etc

Thanks

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Thanks for opening the PR. One thing I’m not entirely convinced about is whether this should be a refactoring actions that modifies the current source file. I would probably have implemented this as a code action that shows a message with the Objective-C selector name to the user via the window/showMessageRequest request if the client supports that request. What do you think about that approach?

@iMostfa iMostfa force-pushed the push-tpunonyzorpx branch 3 times, most recently from a84590e to 44a8a3c Compare December 22, 2025 11:54
@iMostfa
Copy link
Contributor Author

iMostfa commented Dec 22, 2025

@ahoppen
Thanks for the quick review !
yup, i think it's more convenient, and won't need to depend on workspace/executeCommand in the client.
i will work on modifying.

@iMostfa
Copy link
Contributor Author

iMostfa commented Dec 23, 2025

Screen.Recording.2025-12-23.at.1.10.07.AM.mov

@ahoppen I tried to use window/showMessageRequest but i found that we won't provide any actions, So instead I used window/showMessage which works by just showing a message

e37ec29

After giving it more thought, I think it’s more useful to add the Objective-C selector as a comment rather than only showing it in a dialog.

The most common use case for this action is likely copying the selector to use it in an Objective-C file. While it’s possible to move the mouse and copy it from the dialog, it’s more convenient to stay on the keyboard and simply navigate to and select the comment.

Do you think it makes sense to prefer adding a comment in this case?

@ahoppen
Copy link
Member

ahoppen commented Dec 23, 2025

After giving it more thought, I think it’s more useful to add the Objective-C selector as a comment rather than only showing it in a dialog.

The most common use case for this action is likely copying the selector to use it in an Objective-C file. While it’s possible to move the mouse and copy it from the dialog, it’s more convenient to stay on the keyboard and simply navigate to and select the comment.

Do you think it makes sense to prefer adding a comment in this case?

My thoughts are that the Objective-C selector name is a transient bit of information that you are very unlikely to want to keep around in your source file. While I agree that copying may be easier if the selector gets added as a comment, I see two downsides (both not big, but still): We give a small indication that it may be a good pattern to keep the Objective-C selector of these functions around in your source file, which I don’t want to give. Furthermore, you need to remember to remove the comment again after copying the selector name. And doing so may counteract any workflow advantages from putting the selector in the source file.

@iMostfa
Copy link
Contributor Author

iMostfa commented Dec 23, 2025

fair points, so, if we decide to continue with just showMessage request, maybe we can rename the code action to be "Show Objective-c selector" instead of "Copy Objective-c selector" ?

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.

Add Action to Copy Objective-C Selector Name of @objc Swift Method

2 participants