Remove CancellationToken

This is no longer needed because we handle cancellation on the `Task` level.
This commit is contained in:
Alex Hoppen
2023-10-04 08:18:24 -07:00
parent 3d17caded6
commit 71dfd489ae
7 changed files with 3 additions and 49 deletions

View File

@@ -129,9 +129,7 @@ public final class TestMessageHandler: MessageHandler {
from clientID: ObjectIdentifier,
reply: @escaping (LSPResult<R.Response>) -> Void
) {
let cancellationToken = CancellationToken()
let request = Request(params, id: id, clientID: clientID, cancellation: cancellationToken, reply: reply)
let request = Request(params, id: id, clientID: clientID, reply: reply)
guard !oneShotRequestHandlers.isEmpty else {
fatalError("unexpected request \(request)")
@@ -179,14 +177,11 @@ public final class TestServer: MessageHandler {
from clientID: ObjectIdentifier,
reply: @escaping (LSPResult<R.Response>) -> Void
) {
let cancellationToken = CancellationToken()
if let params = params as? EchoRequest {
let req = Request(
params,
id: id,
clientID: clientID,
cancellation: cancellationToken,
reply: { result in
reply(result.map({ $0 as! R.Response }))
}
@@ -197,7 +192,6 @@ public final class TestServer: MessageHandler {
params,
id: id,
clientID: clientID,
cancellation: cancellationToken,
reply: { result in
reply(result.map({ $0 as! R.Response }))
}

View File

@@ -1,6 +1,5 @@
add_library(LanguageServerProtocol STATIC
AsyncQueue.swift
Cancellation.swift
Connection.swift
CustomCodable.swift
Error.swift

View File

@@ -1,27 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// TODO: implement
public final class CancellationToken {
public var isCancelled: Bool { return false }
public init() {}
public func addCancellationHandler(_ handler: @escaping () -> Void) {
}
public func cancel() {
}
}

View File

@@ -157,9 +157,9 @@ extension Connection {
/// use the version with a completion handler.
public func send<R: RequestType>(_ request: R) async throws -> R.Response {
let requestIDWrapper = ThreadSafeBox<RequestID?>(initialValue: nil)
try Task.checkCancellation()
return try await withTaskCancellationHandler {
try await withCheckedThrowingContinuation { continuation in
try Task.checkCancellation()
return try await withCheckedThrowingContinuation { continuation in
let requestID = self.send(request) { result in
continuation.resume(with: result)
}

View File

@@ -38,20 +38,15 @@ public final class Request<R: RequestType> {
}
}
/// The request's cancellation state.
public let cancellationToken: CancellationToken
public init(
_ request: Params,
id: RequestID,
clientID: ObjectIdentifier,
cancellation: CancellationToken,
reply: @escaping (LSPResult<Response>) -> Void
) {
self.id = id
self.clientID = clientID
self.params = request
self.cancellationToken = cancellation
self.replyBlock = reply
}
@@ -71,9 +66,6 @@ public final class Request<R: RequestType> {
public func reply(_ result: Response) {
reply(.success(result))
}
/// Whether the result has been cancelled.
public var isCancelled: Bool { return cancellationToken.isCancelled }
}
/// A request object, wrapping the parameters of a `NotificationType`.

View File

@@ -298,7 +298,6 @@ actor ClangLanguageServerShim: ToolchainLanguageServer, MessageHandler {
params,
id: id,
clientID: clientID,
cancellation: CancellationToken(),
reply: { result in
reply(result)
}

View File

@@ -703,13 +703,10 @@ extension SourceKitServer: MessageHandler {
) async {
let startDate = Date()
let cancellationToken = CancellationToken()
let request = Request(
params,
id: id,
clientID: clientID,
cancellation: cancellationToken,
reply: { [weak self] result in
reply(result)
let endDate = Date()