mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This moves the swift-lang library out of the tools/SourceKit directory and into the stdlib directory. As it stands, the library required that the standard library and the SDK overlay was being built. This is implicitly done when building the stdlib subdirectory. Furthermore, it had an odd tie between the flags for Swift and SourceKit which now have the logic separated. This clearly delineates the host and target components in the repository.
44 lines
1.6 KiB
Swift
44 lines
1.6 KiB
Swift
//===--------------------- SourceKitdClient.swift -------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
// This file provides a wrapper of SourceKitd service.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import sourcekitd
|
|
|
|
public class SourceKitdService {
|
|
|
|
public init() {
|
|
sourcekitd_initialize()
|
|
}
|
|
deinit {
|
|
sourcekitd_shutdown()
|
|
}
|
|
|
|
/// Send a request synchronously with a handler for its response.
|
|
/// - Parameter request: The request to send.
|
|
/// - Returns: The response from the sourcekitd service.
|
|
public func sendSyn(request: SourceKitdRequest) -> SourceKitdResponse {
|
|
return SourceKitdResponse(resp: sourcekitd_send_request_sync(request.rawRequest))
|
|
}
|
|
|
|
/// Send a request asynchronously with a handler for its response.
|
|
/// - Parameter request: The request to send.
|
|
/// - Parameter handler: The handler for the response in the future.
|
|
public func send(request: SourceKitdRequest,
|
|
handler: @escaping (SourceKitdResponse) -> ()) {
|
|
sourcekitd_send_request(request.rawRequest, nil) { response in
|
|
guard let response = response else { return }
|
|
handler(SourceKitdResponse(resp: response))
|
|
}
|
|
}
|
|
}
|