fix: honor supported_protocol_versions when negotiating initialize (#1093)
This commit is contained in:
parent
51c8ee60e3
commit
d272389fd4
1 changed files with 246 additions and 16 deletions
|
|
@ -460,12 +460,18 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Echoes the client-requested version if known; otherwise returns `server_fallback`.
|
||||
/// Echoes the client-requested version if the server supports it; otherwise
|
||||
/// returns `server_fallback`.
|
||||
///
|
||||
/// `server_supported` comes from [`Service::supported_protocol_versions`], so a
|
||||
/// server that narrows that list is never made to answer `initialize` with a
|
||||
/// version it cannot serve.
|
||||
pub(crate) fn negotiate_protocol_version(
|
||||
client_requested: &ProtocolVersion,
|
||||
server_fallback: ProtocolVersion,
|
||||
server_supported: &[ProtocolVersion],
|
||||
) -> ProtocolVersion {
|
||||
if ProtocolVersion::KNOWN_VERSIONS.contains(client_requested) {
|
||||
if server_supported.contains(client_requested) {
|
||||
client_requested.clone()
|
||||
} else {
|
||||
tracing::warn!(
|
||||
|
|
@ -578,8 +584,11 @@ where
|
|||
return Err(ServerInitializeError::InitializeFailed(e));
|
||||
}
|
||||
};
|
||||
init_response.protocol_version =
|
||||
negotiate_protocol_version(&requested_protocol_version, init_response.protocol_version);
|
||||
init_response.protocol_version = negotiate_protocol_version(
|
||||
&requested_protocol_version,
|
||||
init_response.protocol_version,
|
||||
&service.supported_protocol_versions(),
|
||||
);
|
||||
// Update peer_info so context.protocol_version() reflects the negotiated
|
||||
// version in all subsequent request handlers.
|
||||
negotiated_peer_info.protocol_version = init_response.protocol_version.clone();
|
||||
|
|
|
|||
Loading…
Reference in a new issue