From e4372a09c4eecc6bff45a41b37b251abfe746a04 Mon Sep 17 00:00:00 2001 From: Noah Santschi-Cooney Date: Mon, 6 Jun 2022 18:15:37 +0100 Subject: [PATCH] implement getting reference to inner server from service and router --- src/jsonrpc/router.rs | 5 +++++ src/service.rs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/jsonrpc/router.rs b/src/jsonrpc/router.rs index 0a70ec91..25bf4ef1 100644 --- a/src/jsonrpc/router.rs +++ b/src/jsonrpc/router.rs @@ -32,6 +32,11 @@ impl Router { } } + /// Returns a reference to the inner server. + pub fn inner(&self) -> &S { + self.server.as_ref() + } + /// Registers a new RPC method which constructs a response with the given `callback`. /// /// The `layer` argument can be used to inject middleware into the method handler, if desired. diff --git a/src/service.rs b/src/service.rs index 81825272..c32cc20e 100644 --- a/src/service.rs +++ b/src/service.rs @@ -93,6 +93,11 @@ impl LspService { socket, } } + + /// Returns a reference to the inner server. + pub fn inner(&self) -> &S { + self.inner.inner() + } } impl Service for LspService { @@ -373,4 +378,34 @@ mod tests { let ok = Response::from_ok(1.into(), json!(123i32)); assert_eq!(response, Ok(Some(ok))); } + + #[tokio::test(flavor = "current_thread")] + #[allow(deprecated)] + async fn get_inner() { + let (service, _) = LspService::build(|_| Mock).finish(); + + service + .inner() + .initialize(InitializeParams { + process_id: None, + root_path: None, + root_uri: None, + initialization_options: None, + capabilities: ClientCapabilities { + workspace: None, + text_document: None, + window: None, + general: None, + experimental: None, + #[cfg(feature = "proposed")] + offset_encoding: None, + }, + trace: None, + workspace_folders: None, + client_info: None, + locale: None, + }) + .await + .unwrap(); + } }