in Sources/SourceKitLSP/Swift/SwiftLanguageServer.swift [1123:1158]
func retrieveRefactorCodeActions(_ params: CodeActionRequest, completion: @escaping CodeActionProviderCompletion) {
let additionalCursorInfoParameters: ((SKDRequestDictionary) -> Void) = { skreq in
skreq[self.keys.retrieve_refactor_actions] = 1
}
_cursorInfo(
params.textDocument.uri,
params.range,
additionalParameters: additionalCursorInfoParameters)
{ result in
guard let dict: CursorInfo = result.success ?? nil else {
if let failure = result.failure {
let message = "failed to find refactor actions: \(failure)"
log(message)
completion(.failure(.unknown(message)))
} else {
completion(.failure(.unknown("CursorInfo failed.")))
}
return
}
guard let refactorActions = dict.refactorActions else {
completion(.success([]))
return
}
let codeActions: [CodeAction] = refactorActions.compactMap {
do {
let lspCommand = try $0.asCommand()
return CodeAction(title: $0.title, kind: .refactor, command: lspCommand)
} catch {
log("Failed to convert SwiftCommand to Command type: \(error)", level: .error)
return nil
}
}
completion(.success(codeActions))
}
}