Skip to content

Commit

Permalink
implement getting reference to inner server from service and router
Browse files Browse the repository at this point in the history
  • Loading branch information
Strum355 committed Jun 7, 2022
1 parent dfcdd1d commit e4372a0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/jsonrpc/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ impl<S: Send + Sync + 'static, E> Router<S, E> {
}
}

/// 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.
Expand Down
35 changes: 35 additions & 0 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ impl<S: LanguageServer> LspService<S> {
socket,
}
}

/// Returns a reference to the inner server.
pub fn inner(&self) -> &S {
self.inner.inner()
}
}

impl<S: LanguageServer> Service<Request> for LspService<S> {
Expand Down Expand Up @@ -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();
}
}

0 comments on commit e4372a0

Please sign in to comment.