Skip to content

Commit 4238344

Browse files
committed
Remove CancellationToken
This is no longer needed because we handle cancellation on the `Task` level.
1 parent 38e42fc commit 4238344

File tree

7 files changed

+8
-49
lines changed

7 files changed

+8
-49
lines changed

Sources/LSPTestSupport/TestJSONRPCConnection.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ public final class TestClient: MessageHandler {
136136
}
137137

138138
public func handle<R: RequestType>(_ params: R, id: RequestID, from clientID: ObjectIdentifier, reply: @escaping (LSPResult<R.Response>) -> Void) {
139-
let cancellationToken = CancellationToken()
140-
141-
let request = Request(params, id: id, clientID: clientID, cancellation: cancellationToken, reply: reply)
139+
let request = Request(params, id: id, clientID: clientID, reply: reply)
142140

143141
guard !oneShotRequestHandlers.isEmpty else {
144142
fatalError("unexpected request \(request)")
@@ -228,15 +226,13 @@ public final class TestServer: MessageHandler {
228226
}
229227

230228
public func handle<R: RequestType>(_ params: R, id: RequestID, from clientID: ObjectIdentifier, reply: @escaping (LSPResult<R.Response >) -> Void) {
231-
let cancellationToken = CancellationToken()
232-
233229
if let params = params as? EchoRequest {
234-
let req = Request(params, id: id, clientID: clientID, cancellation: cancellationToken, reply: { result in
230+
let req = Request(params, id: id, clientID: clientID, reply: { result in
235231
reply(result.map({ $0 as! R.Response }))
236232
})
237233
req.reply(req.params.string)
238234
} else if let params = params as? EchoError {
239-
let req = Request(params, id: id, clientID: clientID, cancellation: cancellationToken, reply: { result in
235+
let req = Request(params, id: id, clientID: clientID, reply: { result in
240236
reply(result.map({ $0 as! R.Response }))
241237
})
242238
if let code = req.params.code {

Sources/LanguageServerProtocol/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
add_library(LanguageServerProtocol STATIC
22
AsyncQueue.swift
3-
Cancellation.swift
43
Connection.swift
54
CustomCodable.swift
65
Error.swift

Sources/LanguageServerProtocol/Cancellation.swift

Lines changed: 0 additions & 27 deletions
This file was deleted.

Sources/LanguageServerProtocol/Connection.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ extension Connection {
149149
/// use the version with a completion handler.
150150
public func send<R: RequestType>(_ request: R) async throws -> R.Response {
151151
let requestIDWrapper = ThreadSafeBox<RequestID?>(initialValue: nil)
152-
try Task.checkCancellation()
153152
return try await withTaskCancellationHandler {
154-
try await withCheckedThrowingContinuation { continuation in
153+
try Task.checkCancellation()
154+
return try await withCheckedThrowingContinuation { continuation in
155155
let requestID = self.send(request) { result in
156156
continuation.resume(with: result)
157157
}

Sources/LanguageServerProtocol/Request.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,10 @@ public final class Request<R: RequestType> {
3535
}
3636
}
3737

38-
/// The request's cancellation state.
39-
public let cancellationToken: CancellationToken
40-
41-
public init(_ request: Params, id: RequestID, clientID: ObjectIdentifier, cancellation: CancellationToken, reply: @escaping (LSPResult<Response>) -> Void) {
38+
public init(_ request: Params, id: RequestID, clientID: ObjectIdentifier, reply: @escaping (LSPResult<Response>) -> Void) {
4239
self.id = id
4340
self.clientID = clientID
4441
self.params = request
45-
self.cancellationToken = cancellation
4642
self.replyBlock = reply
4743
}
4844

@@ -62,9 +58,6 @@ public final class Request<R: RequestType> {
6258
public func reply(_ result: Response) {
6359
reply(.success(result))
6460
}
65-
66-
/// Whether the result has been cancelled.
67-
public var isCancelled: Bool { return cancellationToken.isCancelled }
6861
}
6962

7063
/// A request object, wrapping the parameters of a `NotificationType`.

Sources/SourceKitLSP/Clang/ClangLanguageServer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ actor ClangLanguageServerShim: ToolchainLanguageServer, MessageHandler {
285285
reply: @escaping (LSPResult<R.Response>) -> Void
286286
) {
287287
clangdMessageHandlingQueue.async {
288-
let request = Request(params, id: id, clientID: clientID, cancellation: CancellationToken(), reply: { result in
288+
let request = Request(params, id: id, clientID: clientID, reply: { result in
289289
reply(result)
290290
})
291291
guard let sourceKitServer = await self.sourceKitServer else {

Sources/SourceKitLSP/SourceKitServer.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,7 @@ extension SourceKitServer: MessageHandler {
520520
// more results for this completion session after it has received the
521521
// initial results.
522522
let task = messageHandlingQueue.async(barrier: false) {
523-
let cancellationToken = CancellationToken()
524-
525-
let request = Request(params, id: id, clientID: clientID, cancellation: cancellationToken, reply: { [weak self] result in
523+
let request = Request(params, id: id, clientID: clientID, reply: { [weak self] result in
526524
reply(result)
527525
if let self {
528526
Task {

0 commit comments

Comments
 (0)