Skip to content

Commit 7c46df3

Browse files
committed
Remove clientID from request handling
The client ID was needed when a `MessageHandler` could handle messages from multiple connections. We don’t support this anymore (because it wasn’t needed) and so the client ID doesn’t need to get passed through as well.
1 parent 1fe7978 commit 7c46df3

File tree

10 files changed

+29
-42
lines changed

10 files changed

+29
-42
lines changed

Sources/LSPTestSupport/TestJSONRPCConnection.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public actor TestMessageHandler: MessageHandler {
106106
}
107107

108108
/// The LSP server sent a notification to the client. Handle it.
109-
public nonisolated func handle(_ notification: some NotificationType, from clientID: ObjectIdentifier) {
109+
public nonisolated func handle(_ notification: some NotificationType) {
110110
messageHandlingQueue.async {
111111
await self.handleNotificationImpl(notification)
112112
}
@@ -125,7 +125,6 @@ public actor TestMessageHandler: MessageHandler {
125125
public nonisolated func handle<Request: RequestType>(
126126
_ request: Request,
127127
id: RequestID,
128-
from clientID: ObjectIdentifier,
129128
reply: @escaping (LSPResult<Request.Response>) -> Void
130129
) {
131130
reply(.failure(.methodNotFound(Request.method)))
@@ -154,7 +153,7 @@ public final class TestServer: MessageHandler {
154153
self.client = client
155154
}
156155

157-
public func handle(_ params: some NotificationType, from clientID: ObjectIdentifier) {
156+
public func handle(_ params: some NotificationType) {
158157
if params is EchoNotification {
159158
self.client.send(params)
160159
} else {
@@ -165,7 +164,6 @@ public final class TestServer: MessageHandler {
165164
public func handle<R: RequestType>(
166165
_ params: R,
167166
id: RequestID,
168-
from clientID: ObjectIdentifier,
169167
reply: @escaping (LSPResult<R.Response>) -> Void
170168
) {
171169
if let params = params as? EchoRequest {

Sources/LanguageServerProtocol/Connection.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public protocol MessageHandler: AnyObject {
3333
/// The method should return as soon as the notification has been sufficiently
3434
/// handled to avoid out-of-order requests, e.g. once the notification has
3535
/// been forwarded to clangd.
36-
func handle(_ params: some NotificationType, from clientID: ObjectIdentifier)
36+
func handle(_ params: some NotificationType)
3737

3838
/// Handle a request and (asynchronously) receive a reply.
3939
///
@@ -42,9 +42,8 @@ public protocol MessageHandler: AnyObject {
4242
/// request has been sent to sourcekitd. The actual semantic computation
4343
/// should occur after the method returns and report the result via `reply`.
4444
func handle<Request: RequestType>(
45-
_ params: Request,
45+
_ request: Request,
4646
id: RequestID,
47-
from clientID: ObjectIdentifier,
4847
reply: @escaping (LSPResult<Request.Response>) -> Void
4948
)
5049
}
@@ -108,7 +107,7 @@ public final class LocalConnection: @unchecked Sendable {
108107

109108
extension LocalConnection: Connection {
110109
public func send<Notification>(_ notification: Notification) where Notification: NotificationType {
111-
self.handler?.handle(notification, from: ObjectIdentifier(self))
110+
self.handler?.handle(notification)
112111
}
113112

114113
public func send<Request: RequestType>(
@@ -123,7 +122,7 @@ extension LocalConnection: Connection {
123122
}
124123

125124
precondition(self.state == .started)
126-
handler.handle(request, id: id, from: ObjectIdentifier(self)) { result in
125+
handler.handle(request, id: id) { result in
127126
reply(result)
128127
}
129128

Sources/LanguageServerProtocol/Message.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public protocol _RequestType: MessageType {
2626
func _handle(
2727
_ handler: MessageHandler,
2828
id: RequestID,
29-
connection: Connection,
3029
reply: @escaping (LSPResult<ResponseType>, RequestID) -> Void
3130
)
3231
}
@@ -52,18 +51,17 @@ extension RequestType {
5251
public func _handle(
5352
_ handler: MessageHandler,
5453
id: RequestID,
55-
connection: Connection,
5654
reply: @escaping (LSPResult<ResponseType>, RequestID) -> Void
5755
) {
58-
handler.handle(self, id: id, from: ObjectIdentifier(connection)) { response in
56+
handler.handle(self, id: id) { response in
5957
reply(response.map({ $0 as ResponseType }), id)
6058
}
6159
}
6260
}
6361

6462
extension NotificationType {
65-
public func _handle(_ handler: MessageHandler, connection: Connection) {
66-
handler.handle(self, from: ObjectIdentifier(connection))
63+
public func _handle(_ handler: MessageHandler) {
64+
handler.handle(self)
6765
}
6866
}
6967

Sources/LanguageServerProtocolJSONRPC/JSONRPCConnection.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ public final class JSONRPCConnection {
288288
func handle(_ message: JSONRPCMessage) {
289289
switch message {
290290
case .notification(let notification):
291-
notification._handle(self.receiveHandler!, connection: self)
291+
notification._handle(self.receiveHandler!)
292292
case .request(let request, id: let id):
293293
let semaphore: DispatchSemaphore? = syncRequests ? .init(value: 0) : nil
294-
request._handle(self.receiveHandler!, id: id, connection: self) { (response, id) in
294+
request._handle(self.receiveHandler!, id: id) { (response, id) in
295295
self.sendReply(response, id: id)
296296
semaphore?.signal()
297297
}

Sources/SKCore/BuildServerBuildSystem.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public actor BuildServerBuildSystem: MessageHandler {
190190
/// the build server has sent us a notification.
191191
///
192192
/// We need to notify the delegate about any updated build settings.
193-
public nonisolated func handle(_ params: some NotificationType, from clientID: ObjectIdentifier) {
193+
public nonisolated func handle(_ params: some NotificationType) {
194194
logger.info(
195195
"""
196196
Received notification from build server:
@@ -212,7 +212,6 @@ public actor BuildServerBuildSystem: MessageHandler {
212212
public nonisolated func handle<R: RequestType>(
213213
_ params: R,
214214
id: RequestID,
215-
from clientID: ObjectIdentifier,
216215
reply: @escaping (LSPResult<R.Response>) -> Void
217216
) {
218217
logger.info(

Sources/SKTestSupport/TestSourceKitLSPClient.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public final class TestSourceKitLSPClient: MessageHandler {
166166
// deinits, we could await the sending of a ShutdownRequest.
167167
let sema = DispatchSemaphore(value: 0)
168168
nextRequestID += 1
169-
server.handle(ShutdownRequest(), id: .number(nextRequestID), from: ObjectIdentifier(self)) { result in
169+
server.handle(ShutdownRequest(), id: .number(nextRequestID)) { result in
170170
sema.signal()
171171
}
172172
sema.wait()
@@ -184,15 +184,15 @@ public final class TestSourceKitLSPClient: MessageHandler {
184184
public func send<R: RequestType>(_ request: R) async throws -> R.Response {
185185
nextRequestID += 1
186186
return try await withCheckedThrowingContinuation { continuation in
187-
server.handle(request, id: .number(self.nextRequestID), from: ObjectIdentifier(self)) { result in
187+
server.handle(request, id: .number(self.nextRequestID)) { result in
188188
continuation.resume(with: result)
189189
}
190190
}
191191
}
192192

193193
/// Send the notification to `server`.
194194
public func send(_ notification: some NotificationType) {
195-
server.handle(notification, from: ObjectIdentifier(self))
195+
server.handle(notification)
196196
}
197197

198198
// MARK: - Handling messages sent to the editor
@@ -276,7 +276,7 @@ public final class TestSourceKitLSPClient: MessageHandler {
276276

277277
/// - Important: Implementation detail of `TestSourceKitServer`. Do not call
278278
/// from tests.
279-
public func handle(_ params: some NotificationType, from clientID: ObjectIdentifier) {
279+
public func handle(_ params: some NotificationType) {
280280
notificationYielder.yield(params)
281281
}
282282

@@ -285,7 +285,6 @@ public final class TestSourceKitLSPClient: MessageHandler {
285285
public func handle<Request: RequestType>(
286286
_ params: Request,
287287
id: LanguageServerProtocol.RequestID,
288-
from clientID: ObjectIdentifier,
289288
reply: @escaping (LSPResult<Request.Response>) -> Void
290289
) {
291290
guard let requestHandler = requestHandlers.first else {
@@ -403,20 +402,19 @@ private class WeakMessageHandler: MessageHandler {
403402
self.handler = handler
404403
}
405404

406-
func handle(_ params: some LanguageServerProtocol.NotificationType, from clientID: ObjectIdentifier) {
407-
handler?.handle(params, from: clientID)
405+
func handle(_ params: some LanguageServerProtocol.NotificationType) {
406+
handler?.handle(params)
408407
}
409408

410409
func handle<Request: RequestType>(
411410
_ params: Request,
412411
id: LanguageServerProtocol.RequestID,
413-
from clientID: ObjectIdentifier,
414412
reply: @escaping (LanguageServerProtocol.LSPResult<Request.Response>) -> Void
415413
) {
416414
guard let handler = handler else {
417415
reply(.failure(.unknown("Handler has been deallocated")))
418416
return
419417
}
420-
handler.handle(params, id: id, from: clientID, reply: reply)
418+
handler.handle(params, id: id, reply: reply)
421419
}
422420
}

Sources/SourceKitLSP/Clang/ClangLanguageServer.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ actor ClangLanguageServerShim: ToolchainLanguageServer, MessageHandler {
302302
/// sending a notification that's intended for the editor.
303303
///
304304
/// We should either handle it ourselves or forward it to the editor.
305-
nonisolated func handle(_ params: some NotificationType, from clientID: ObjectIdentifier) {
305+
nonisolated func handle(_ params: some NotificationType) {
306306
logger.info(
307307
"""
308308
Received notification from clangd:
@@ -328,7 +328,6 @@ actor ClangLanguageServerShim: ToolchainLanguageServer, MessageHandler {
328328
nonisolated func handle<R: RequestType>(
329329
_ params: R,
330330
id: RequestID,
331-
from clientID: ObjectIdentifier,
332331
reply: @escaping (LSPResult<R.Response>) -> Void
333332
) {
334333
logger.info(

Sources/SourceKitLSP/SourceKitServer.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ private func getNextNotificationIDForLogging() -> Int {
795795
}
796796

797797
extension SourceKitServer: MessageHandler {
798-
public nonisolated func handle(_ params: some NotificationType, from clientID: ObjectIdentifier) {
798+
public nonisolated func handle(_ params: some NotificationType) {
799799
if let params = params as? CancelRequestNotification {
800800
// Request cancellation needs to be able to overtake any other message we
801801
// are currently handling. Ordering is not important here. We thus don't
@@ -815,13 +815,13 @@ extension SourceKitServer: MessageHandler {
815815
// See comment in `withLoggingScope`.
816816
// The last 2 digits should be sufficient to differentiate between multiple concurrently running notifications.
817817
await withLoggingScope("notification-\(notificationID % 100)") {
818-
await self.handleImpl(params, from: clientID)
818+
await self.handleImpl(params)
819819
signposter.endInterval("Notification", state, "Done")
820820
}
821821
}
822822
}
823823

824-
private func handleImpl(_ notification: some NotificationType, from clientID: ObjectIdentifier) async {
824+
private func handleImpl(_ notification: some NotificationType) async {
825825
logger.log("Received notification: \(notification.forLogging)")
826826

827827
switch notification {
@@ -852,7 +852,6 @@ extension SourceKitServer: MessageHandler {
852852
public nonisolated func handle<R: RequestType>(
853853
_ params: R,
854854
id: RequestID,
855-
from clientID: ObjectIdentifier,
856855
reply: @escaping (LSPResult<R.Response>) -> Void
857856
) {
858857
let signposter = Logger(subsystem: subsystem, category: "request-\(id)").makeSignposter()
@@ -865,7 +864,7 @@ extension SourceKitServer: MessageHandler {
865864
// See comment in `withLoggingScope`.
866865
// The last 2 digits should be sufficient to differentiate between multiple concurrently running requests.
867866
await withLoggingScope("request-\(id.numericValue % 100)") {
868-
await self.handleImpl(params, id: id, from: clientID, reply: reply)
867+
await self.handleImpl(params, id: id, reply: reply)
869868
signposter.endInterval("Request", state, "Done")
870869
}
871870
// We have handled the request and can't cancel it anymore.
@@ -885,7 +884,6 @@ extension SourceKitServer: MessageHandler {
885884
private func handleImpl<R: RequestType>(
886885
_ params: R,
887886
id: RequestID,
888-
from clientID: ObjectIdentifier,
889887
reply: @escaping (LSPResult<R.Response>) -> Void
890888
) async {
891889
let startDate = Date()

Tests/LanguageServerProtocolJSONRPCTests/ConnectionTests.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,11 @@ class ConnectionTests: XCTestCase {
258258
)
259259

260260
final class DummyHandler: MessageHandler {
261-
func handle<N: NotificationType>(_: N, from: ObjectIdentifier) {}
262-
func handle<R: RequestType>(
263-
_: R,
261+
func handle(_: some NotificationType) {}
262+
func handle<Request: RequestType>(
263+
_ request: Request,
264264
id: RequestID,
265-
from: ObjectIdentifier,
266-
reply: @escaping (LSPResult<R.Response>) -> Void
265+
reply: @escaping (LSPResult<Request.Response>) -> Void
267266
) {}
268267
}
269268

Tests/SourceKitLSPTests/LifecycleTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ final class LifecycleTests: XCTestCase {
6666
let requestID = RequestID.string("cancellation-test")
6767
testClient.server.handle(
6868
CompletionRequest(textDocument: TextDocumentIdentifier(uri), position: positions["2️⃣"]),
69-
id: requestID,
70-
from: ObjectIdentifier(self)
69+
id: requestID
7170
) { reply in
7271
switch reply {
7372
case .success:

0 commit comments

Comments
 (0)