-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement getting a reference to the inner server from LspService
and Router
#344
Conversation
d4b75c6
to
e4372a0
Compare
Thanks for the PR. I can definitely see how this can make things a little more immediate as far as testing is concerned. I'm not sure whether it's a good idea to provide a method like this in general although I don't really have a strong opinion for it or against it. I suppose one possibility could be to only enable/compile Any thoughts @ebkalderon? |
Unfortunately I dont think thats currently supported by rust 😔 rust-lang/cargo#8379 |
Thanks for looping me in! I don't have a particularly strong stance for or against this addition either. Personally, when I write servers I try to make the underlying state machine easily testable on its own without needing access to I wonder why wrapping Perhaps we could approach this shortcoming another way by instead shipping a test harness of some kind with use tower_lsp::test;
#[tokio::test(flavor = "current_thread")]
async fn test_server() {
// This sets up a `Client` and `ClientSocket` pair that allow for
// manual testing of the server.
//
// The returned tuple is of type `(Arc<Mock>, ClientSocket)`.
let (server, mut socket) = test::server(|client| Mock { client });
// Call `LanguageServer` methods directly, examine internal state, etc.
assert!(server.initialize(...).await.is_ok());
// Let's assume one server method must make a client request.
let s = server.clone();
let handle = tokio::spawn(async move { s.initialized(...).await });
// Reply to the request as if we were the client.
let request = socket.next().await.unwrap();
socket.send(...).await.unwrap();
// We can still inspect `server`'s state and call other methods
///at any time during this.
let response = handle.await.unwrap();
assert!(response.is_ok());
} Any thoughts on this idea? It could be used either as an alternative to or in conjunction with this PR's approach. |
That raises a good point I hadn't made the connection with before, seeing as I'd have direct access to my |
The utility for this is mostly in testing, wherein I want to be able to test inner state of the server contained within the
LspService
. This avoids the need to use thecustom_method
feature as a workaround, as the constraints on types returned and ceremony around sending/receiving jsonrpc messages is too much hassle imo.Have tested this locally with my own
LanguageServer
impl and all seemed 🆗 so far 🙂