@@ -965,13 +965,23 @@ extension SwiftLanguageService {
965965
966966 var canInlineMacro = false
967967
968- var refactorActions = cursorInfoResponse. refactorActions. compactMap {
969- let lspCommand = $0. asCommand ( )
968+ var refactorActions : [ CodeAction ] = cursorInfoResponse. refactorActions. compactMap { action in
969+ if action. actionString == " source.refactoring.kind.copy.objc.selector " {
970+ let copyCommand = CopyObjCSelectorCommand (
971+ title: " Copy Objective-C Selector " ,
972+ actionString: action. actionString,
973+ positionRange: params. range,
974+ textDocument: params. textDocument
975+ ) . asCommand ( )
976+ return CodeAction ( title: " Copy Objective-C Selector " , kind: . refactor, command: copyCommand)
977+ }
978+
979+ let lspCommand = action. asCommand ( )
970980 if !canInlineMacro {
971- canInlineMacro = $0 . actionString == " source.refactoring.kind.inline.macro "
981+ canInlineMacro = action . actionString == " source.refactoring.kind.inline.macro "
972982 }
973983
974- return CodeAction ( title: $0 . title, kind: . refactor, command: lspCommand)
984+ return CodeAction ( title: action . title, kind: . refactor, command: lspCommand)
975985 }
976986
977987 if canInlineMacro {
@@ -981,51 +991,9 @@ extension SwiftLanguageService {
981991 refactorActions. append ( CodeAction ( title: expandMacroCommand. title, kind: . refactor, command: expandMacroCommand) )
982992 }
983993
984- if let copySelectorAction = await makeCopyObjCSelectorAction (
985- range: params. range,
986- textDocument: params. textDocument,
987- snapshot: snapshot
988- ) {
989- refactorActions. append ( copySelectorAction)
990- }
991-
992994 return refactorActions
993995 }
994996
995- private func makeCopyObjCSelectorAction(
996- range: Range < Position > ,
997- textDocument: LanguageServerProtocol . TextDocumentIdentifier ,
998- snapshot: DocumentSnapshot
999- ) async -> CodeAction ? {
1000- let compileCommand = await self . compileCommand ( for: snapshot. uri, fallbackAfterTimeout: true )
1001- let offset = snapshot. utf8Offset ( of: range. lowerBound)
1002-
1003- let keys = self . keys
1004- let primaryFile = snapshot. uri. primaryFile? . pseudoPath
1005- let compilerArgs : [ any SKDRequestValue ] = compileCommand? . compilerArgs ?? [ ]
1006- let skreq = sourcekitd. dictionary ( [
1007- keys. offset: offset,
1008- keys. sourceFile: snapshot. uri. sourcekitdSourceFile,
1009- keys. primaryFile: primaryFile,
1010- keys. compilerArgs: compilerArgs
1011- ] )
1012-
1013- do {
1014- let dict = try await send ( sourcekitdRequest: \. objcSelector, skreq, snapshot: snapshot)
1015- if dict [ keys. text] as String ? != nil {
1016- let copyCommand = CopyObjCSelectorCommand (
1017- positionRange: range,
1018- textDocument: textDocument
1019- ) . asCommand ( )
1020- return CodeAction ( title: " Copy Objective-C Selector " , kind: . refactor, command: copyCommand)
1021- }
1022- } catch {
1023- logger. debug ( " CopyObjCSelector: applicability check failed: \( error. forLogging) " )
1024- }
1025-
1026- return nil
1027- }
1028-
1029997 func retrieveQuickFixCodeActions( _ params: CodeActionRequest ) async throws -> [ CodeAction ] {
1030998 let snapshot = try await self . latestSnapshot ( for: params. textDocument. uri)
1031999 let buildSettings = await self . compileCommand ( for: params. textDocument. uri, fallbackAfterTimeout: true )
0 commit comments