oxalica / async-lsp

Asynchronous Language Server Protocol framework
Apache License 2.0
66 stars 8 forks source link

Will calls on `ServerSocket::request` returned `MainLoop::new_client` applies Tower layers? #11

Open alissa-tung opened 6 months ago

alissa-tung commented 6 months ago

Thank you for developing this library, and

Hello, I had tried two ways creating Tower layers to make some logs:

both approach applies logs for requests from server to client, but does not work for the requests that I filed from client with ServerSocket::request, where the ServerSocket instance is returned by MainLoop::new_client.

My questions are:

I had also tried to use the builder function MainLoop::new_client's server socket argument, use router.request::<ACustomRequest>(|router_state, request| { logging here; return here }). but

oxalica commented 5 months ago
  • will calls on ServerSocket::request returned MainLoop::new_client applies Tower layers?
  • did I miss something or some methods when logging on trait methods fn notify, fn emit and fn call

Unfortunately, no at least for now. It will enqueue the message and send it to the peer directly without extra handlers. You can wrap the *Socket to do that though that will change the type.

I think Tower layers are mainly used to modular services construction, so the local connection API *Socket does not apply. We can wrap tower layers on it, but I don't know how useful it is besides for logging purpose. Also the delay you measured on *Socket::request would be your protocol peer's handling delay, which is outside your control.

  • what is the event in the library?

It is mentioned in LspService::emit. It's a custom message passing method to do stuff synchronously in the main loop, or trigger specific works in the main loop from other threads. Eg. trigger server exit on some conditions maybe from another thread (used by client_monitor here), diagnostic refresh after some delay (timer tick event example here), and etc. Since the event handling is always executed synchronously in the main thread, you can use &mut self without locking and don't need to tangle with async-request reordering.