Skip to content

Conversation

@iMostfa
Copy link
Contributor

@iMostfa iMostfa commented Dec 21, 2025

Resolves: swiftlang/sourcekit-lsp#2145
along with: swiftlang/sourcekit-lsp#2399

example.mov

Add Copy Objective-C Selector Refactoring

This PR adds a new refactoring action that allows users to copy the Objective-C selector from Swift methods marked with @objc or @objcMembers

  • New SourceKit request: source.request.objc.selector - retrieves the Objective-C selector for a method at a given position
  • Refactoring support: Integrated into the semantic refactoring system to provide "Copy Objective-C Selector" as a refactoring action
  • Test coverage: Added comprehensive tests covering simple methods, methods with parameters, and methods with custom selectors

SourceKit API (SwiftSourceDocInfo.cpp:2888-2974):

  • New getObjCSelector method that resolves cursor position to an AbstractFunctionDecl
  • Validates the declaration has @objc annotation
  • Extracts and returns the selector string using getObjCSelector().getString()

Request Handling (Requests.cpp:1767-1813):

  • Added handleRequestGetObjCSelector to process selector extraction requests
  • Returns selector as text via key.text in the response

@iMostfa iMostfa marked this pull request as ready for review December 21, 2025 17:06
@iMostfa iMostfa force-pushed the add-support-to-copy-objc-selector branch from f7449c2 to ff1073e Compare December 21, 2025 17:06
@iMostfa iMostfa force-pushed the add-support-to-copy-objc-selector branch from ff1073e to 0a6aea9 Compare January 4, 2026 00:20
@iMostfa iMostfa changed the title Add support to copy objc selector Add support to show objc selector Jan 4, 2026
- Add `source.request.objc.selector` request handler that returns the
  Objective-C selector for @objc methods
- Fix inverted condition in getInt64 check for offset parameter
- Add `objc-selector` request support to sourcekitd-test for testing
- Add tests for simple methods, parameterized methods, and custom selectors

This implements a direct sourcekitd request approach instead of modeling
it as a refactoring action, providing a cleaner API for retrieving
Objective-C selectors.
iMostfa added a commit to iMostfa/sourcekit-lsp that referenced this pull request Jan 12, 2026
This updates the implementation to use `source.request.objc.selector`
directly instead of intercepting a refactoring action.

Changes:
- ShowObjCSelector.swift: Call `source.request.objc.selector` and read
  the selector from `key.text` in the response
- ShowObjCSelectorCommand.swift: Remove actionString field since we're
  not using refactoring
- SwiftLanguageService.swift: Show "Show Objective-C Selector" action
  for methods/functions/constructors instead of checking for a
  non-existent refactoring action
- sourcekitd_uids.swift: Add `objcSelector` UID for the new request

This aligns with swiftlang/swift#86173 which implements the feature as
a standalone request rather than a refactoring action.
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

1 participant