Skip to content

Embrace Swift.Result in place SwiftPM.Basic.Result #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/LanguageServerProtocol/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension Connection {
semaphore.signal()
}
semaphore.wait()
return try result!.dematerialize()
return try result!.get()
}
}

Expand Down
4 changes: 1 addition & 3 deletions Sources/LanguageServerProtocol/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
//
//===----------------------------------------------------------------------===//

import Basic

/// A convenience wrapper for `Result` where the error is a `ResponseError`.
public typealias LSPResult<T> = Result<T, ResponseError>
public typealias LSPResult<T> = Swift.Result<T, ResponseError>

/// Error code suitable for use between language server and client.
public struct ErrorCode: RawRepresentable, Codable, Hashable {
Expand Down
8 changes: 3 additions & 5 deletions Sources/SKSupport/Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
//
//===----------------------------------------------------------------------===//

import Basic

extension Result {
extension Swift.Result {

/// Project out the .success value, or nil.
public var success: Value? {
public var success: Success? {
switch self {
case .success(let value):
return value
Expand All @@ -25,7 +23,7 @@ extension Result {
}

/// Project out the .failure value, or nil.
public var failure: ErrorType? {
public var failure: Failure? {
switch self {
case .failure(let error):
return error
Expand Down
2 changes: 1 addition & 1 deletion Sources/SourceKit/sourcekitd/CursorInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ extension SwiftLanguageServer {
func cursorInfo(
_ url: URL,
_ position: Position,
_ completion: @escaping (Result<CursorInfo?, CursorInfoError>) -> Void)
_ completion: @escaping (Swift.Result<CursorInfo?, CursorInfoError>) -> Void)
{
guard let snapshot = documentManager.latestSnapshot(url) else {
return completion(.failure(.unknownDocument(url)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ConnectionTests: XCTestCase {
let expectation = self.expectation(description: "response received")

_ = client.send(EchoRequest(string: "hello!")) { resp in
XCTAssertEqual(try! resp.dematerialize(), "hello!")
XCTAssertEqual(try! resp.get(), "hello!")
expectation.fulfill()
}

Expand Down Expand Up @@ -96,7 +96,7 @@ class ConnectionTests: XCTestCase {
let expectation2 = self.expectation(description: "response received 2")

_ = client.send(EchoError(code: nil)) { resp in
XCTAssertEqual(try! resp.dematerialize(), VoidResponse())
XCTAssertEqual(try! resp.get(), VoidResponse())
expectation.fulfill()
}

Expand Down Expand Up @@ -156,7 +156,7 @@ class ConnectionTests: XCTestCase {
// Nothing bad should happen; check that the next request works.

_ = client.send(EchoRequest(string: "hello!")) { resp in
XCTAssertEqual(try! resp.dematerialize(), "hello!")
XCTAssertEqual(try! resp.get(), "hello!")
expectation.fulfill()
}

Expand All @@ -173,7 +173,7 @@ class ConnectionTests: XCTestCase {
// Nothing bad should happen; check that the next request works.

_ = client.send(EchoRequest(string: "hello!")) { resp in
XCTAssertEqual(try! resp.dematerialize(), "hello!")
XCTAssertEqual(try! resp.get(), "hello!")
expectation.fulfill()
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/LanguageServerProtocolTests/ConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ConnectionTests: XCTestCase {
let expectation = self.expectation(description: "response received")

_ = client.send(EchoRequest(string: "hello!")) { resp in
XCTAssertEqual(try! resp.dematerialize(), "hello!")
XCTAssertEqual(try! resp.get(), "hello!")
expectation.fulfill()
}

Expand All @@ -47,7 +47,7 @@ class ConnectionTests: XCTestCase {
let expectation2 = self.expectation(description: "response received 2")

_ = client.send(EchoError(code: nil)) { resp in
XCTAssertEqual(try! resp.dematerialize(), VoidResponse())
XCTAssertEqual(try! resp.get(), VoidResponse())
expectation.fulfill()
}

Expand Down
20 changes: 10 additions & 10 deletions Tests/SKSupportTests/SupportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ final class SupportTests: XCTestCase {
enum MyError: Error, Equatable {
case err1, err2
}
typealias MyResult<T> = Result<T, MyError>
typealias MyResult<T> = Swift.Result<T, MyError>

XCTAssertEqual(MyResult(1), .success(1))
XCTAssertNotEqual(MyResult(2), .success(1))
XCTAssertNotEqual(MyResult(.err1), .success(1))
XCTAssertEqual(MyResult(.err1), MyResult<Int>.failure(.err1))
XCTAssertNotEqual(MyResult(.err1), MyResult<Int>.failure(.err2))
XCTAssertEqual(MyResult.success(1), .success(1))
XCTAssertNotEqual(MyResult.success(2), .success(1))
XCTAssertNotEqual(MyResult.failure(.err1), .success(1))
XCTAssertEqual(MyResult.failure(.err1), MyResult<Int>.failure(.err1))
XCTAssertNotEqual(MyResult.failure(.err1), MyResult<Int>.failure(.err2))
}

func testResultProjection() {
enum MyError: Error, Equatable {
case err1, err2
}
typealias MyResult<T> = Result<T, MyError>
typealias MyResult<T> = Swift.Result<T, MyError>

XCTAssertEqual(MyResult(1).success, 1)
XCTAssertNil(MyResult(.err1).success)
XCTAssertNil(MyResult(1).failure)
XCTAssertEqual(MyResult.success(1).success, 1)
XCTAssertNil(MyResult.failure(.err1).success)
XCTAssertNil(MyResult.success(1).failure)
XCTAssertEqual(MyResult<Int>.failure(.err1).failure, .err1)
}

Expand Down