Skip to content

Commit b22af35

Browse files
committed
Revert asyncificaiton changes
The asyncification changes caused some non-deterministic test failures. I believe that some of these are due to race conditions that are the result of the partial transition to actors. Instead of merging the asyncification piece by piece, I will collect the changes asyncification changes in a branch and then qualify that branch througougly (running CI multiple times) before merging it into `main`.
1 parent 1606e73 commit b22af35

File tree

55 files changed

+2527
-2824
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2527
-2824
lines changed

Sources/LSPLogging/Logging.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,6 @@ public func orLog<R>(
6262
}
6363
}
6464

65-
/// Like `try?`, but logs the error on failure.
66-
public func orLog<R>(
67-
_ prefix: String = "",
68-
level: LogLevel = .default,
69-
logger: Logger = Logger.shared,
70-
_ block: () async throws -> R?) async -> R?
71-
{
72-
do {
73-
return try await block()
74-
} catch {
75-
logger.log("\(prefix)\(prefix.isEmpty ? "" : " ")\(error)", level: level)
76-
return nil
77-
}
78-
}
79-
80-
8165
/// Logs the time that the given block takes to execute in milliseconds.
8266
public func logExecutionTime<R>(
8367
_ prefix: String = #function,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import XCTest
14+
15+
/// Same as `XCTAssertThrows` but executes the trailing closure.
16+
public func assertNoThrow<T>(_ expression: () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #filePath, line: UInt = #line) {
17+
XCTAssertNoThrow(try expression(), message(), file: file, line: line)
18+
}

Sources/LSPTestSupport/Assertions.swift

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

Sources/LanguageServerProtocol/AsyncQueue.swift

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

Sources/LanguageServerProtocol/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
add_library(LanguageServerProtocol STATIC
2-
AsyncQueue.swift
32
Cancellation.swift
43
Connection.swift
54
CustomCodable.swift

Sources/LanguageServerProtocol/Connection.swift

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,10 @@ extension Connection {
4242
public protocol MessageHandler: AnyObject {
4343

4444
/// Handle a notification without a reply.
45-
///
46-
/// The method should return as soon as the notification has been sufficiently
47-
/// handled to avoid out-of-order requests, e.g. once the notification has
48-
/// been forwarded to clangd.
49-
func handle(_ params: some NotificationType, from clientID: ObjectIdentifier) async
45+
func handle(_ params: some NotificationType, from clientID: ObjectIdentifier)
5046

5147
/// Handle a request and (asynchronously) receive a reply.
52-
///
53-
/// The method should return as soon as the request has been sufficiently
54-
/// handled to avoid out-of-order requests, e.g. once the corresponding
55-
/// request has been sent to sourcekitd. The actual semantic computation
56-
/// should occur after the method returns and report the result via `reply`.
57-
func handle<Request: RequestType>(_ params: Request, id: RequestID, from clientID: ObjectIdentifier, reply: @escaping (LSPResult<Request.Response>) -> Void) async
48+
func handle<Request: RequestType>(_ params: Request, id: RequestID, from clientID: ObjectIdentifier, reply: @escaping (LSPResult<Request.Response>) -> Void)
5849
}
5950

6051
/// A connection between two message handlers in the same process.
@@ -75,20 +66,8 @@ public final class LocalConnection {
7566
case ready, started, closed
7667
}
7768

78-
/// The queue guarding `_nextRequestID`.
7969
let queue: DispatchQueue = DispatchQueue(label: "local-connection-queue")
8070

81-
/// The queue on which all messages (notifications, requests, responses) are
82-
/// handled.
83-
///
84-
/// The queue is blocked until the message has been sufficiently handled to
85-
/// avoid out-of-order handling of messages. For sourcekitd, this means that
86-
/// a request has been sent to sourcekitd and for clangd, this means that we
87-
/// have forwarded the request to clangd.
88-
///
89-
/// The actual semantic handling of the message happens off this queue.
90-
let messageHandlingQueue: AsyncQueue = AsyncQueue()
91-
9271
var _nextRequestID: Int = 0
9372

9473
var state: State = .ready
@@ -125,34 +104,22 @@ public final class LocalConnection {
125104

126105
extension LocalConnection: Connection {
127106
public func send<Notification>(_ notification: Notification) where Notification: NotificationType {
128-
messageHandlingQueue.async {
129-
await self.handler?.handle(notification, from: ObjectIdentifier(self))
130-
}
107+
handler?.handle(notification, from: ObjectIdentifier(self))
131108
}
132109

133-
public func send<Request: RequestType>(
134-
_ request: Request,
135-
queue: DispatchQueue,
136-
reply: @escaping (LSPResult<Request.Response>) -> Void
137-
) -> RequestID {
110+
public func send<Request>(_ request: Request, queue: DispatchQueue, reply: @escaping (LSPResult<Request.Response>) -> Void) -> RequestID where Request: RequestType {
138111
let id = nextRequestID()
112+
guard let handler = handler else {
113+
queue.async { reply(.failure(.serverCancelled)) }
114+
return id
115+
}
139116

140-
messageHandlingQueue.async {
141-
guard let handler = self.handler else {
142-
queue.async {
143-
reply(.failure(.serverCancelled))
144-
}
145-
return
146-
}
147-
148-
precondition(self.state == .started)
149-
await handler.handle(request, id: id, from: ObjectIdentifier(self)) { result in
150-
queue.async {
151-
reply(result)
152-
}
117+
precondition(state == .started)
118+
handler.handle(request, id: id, from: ObjectIdentifier(self)) { result in
119+
queue.async {
120+
reply(result)
153121
}
154122
}
155-
156123
return id
157124
}
158125
}

Sources/LanguageServerProtocol/Message.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public protocol _RequestType: MessageType {
2828
id: RequestID,
2929
connection: Connection,
3030
reply: @escaping (LSPResult<ResponseType>, RequestID) -> Void
31-
) async
31+
)
3232
}
3333

3434
/// A request, which must have a unique `method` name as well as an associated response type.
@@ -54,16 +54,16 @@ extension RequestType {
5454
id: RequestID,
5555
connection: Connection,
5656
reply: @escaping (LSPResult<ResponseType>, RequestID) -> Void
57-
) async {
58-
await handler.handle(self, id: id, from: ObjectIdentifier(connection)) { response in
57+
) {
58+
handler.handle(self, id: id, from: ObjectIdentifier(connection)) { response in
5959
reply(response.map({ $0 as ResponseType }), id)
6060
}
6161
}
6262
}
6363

6464
extension NotificationType {
65-
public func _handle(_ handler: MessageHandler, connection: Connection) async {
66-
await handler.handle(self, from: ObjectIdentifier(connection))
65+
public func _handle(_ handler: MessageHandler, connection: Connection) {
66+
handler.handle(self, from: ObjectIdentifier(connection))
6767
}
6868
}
6969

Sources/LanguageServerProtocol/Requests/CodeActionRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
public typealias CodeActionProviderCompletion = (LSPResult<[CodeAction]>) -> Void
14-
public typealias CodeActionProvider = (CodeActionRequest, @escaping CodeActionProviderCompletion) async -> Void
14+
public typealias CodeActionProvider = (CodeActionRequest, @escaping CodeActionProviderCompletion) -> Void
1515

1616
/// Request for returning all possible code actions for a given text document and range.
1717
///

0 commit comments

Comments
 (0)