Skip to content
Merged
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
33 changes: 31 additions & 2 deletions Sources/LanguageServerProtocol/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,19 @@ public protocol Connection: Sendable {
/// Send a request with a pre-defined request ID and (asynchronously) receive a reply.
///
/// The request ID must not conflict with any request ID generated by `nextRequestID()`.
/// `method` is the JSON-RPC method string; pass `Request.method` for the normal case or a
/// legacy method name when talking to an old peer.
func send<Request: RequestType>(
_ request: Request,
id: RequestID,
reply: @escaping @Sendable (LSPResult<Request.Response>) -> Void
)

/// Same as ``send(_:id:reply:)`` but allows overriding the JSON-RPC method
/// string (e.g. a legacy method name when talking to an old peer).
///
/// The default implementation ignores `method` and dispatches to
/// ``send(_:id:reply:)``. Conformers that need to honor the override (typically
/// transport-level connections) should implement this directly. At least one of
/// the two `send` overloads must be implemented to avoid infinite recursion.
func send<Request: RequestType>(
_ request: Request,
method: String,
Expand All @@ -39,6 +50,24 @@ public protocol Connection: Sendable {
}

extension Connection {
@available(*, deprecated, message: "Conformers should implement send(_:id:method:reply:)")
public func send<Request: RequestType>(
_ request: Request,
method: String,
id: RequestID,
reply: @escaping @Sendable (LSPResult<Request.Response>) -> Void
) {
self.send(request, id: id, reply: reply)
}

public func send<Request: RequestType>(
_ request: Request,
id: RequestID,
reply: @escaping @Sendable (LSPResult<Request.Response>) -> Void
) {
self.send(request, method: Request.method, id: id, reply: reply)
Comment on lines +60 to +68

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't say I love the fact that implementing neither will result in infinite recursion instead of a compiler error, would it make sense to at least mark the default implementation of the method variant as deprecated? That way conformers at least get a warning if they don't implement it (if they previously implemented the non-method variant they should just add the method parameter)

}

/// Send a request and (asynchronously) receive a reply.
public func send<Request: RequestType>(
_ request: Request,
Expand Down
Loading