-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate request routing table with a proc macro
This commit adds a new subcrate named `tower-lsp-macros` which exposes an `#[rpc]` procedural macro. This macro annotates each of the `LanguageServer` trait methods and creates a new `crate::generated_impl` module from it, containing two things: 1. An opaque `ServerRequest` struct which uses `serde` derive magic to deserialize valid LSP server requests from JSON, based on the trait methods' type signatures. This `ServerRequest` struct is ready to be re-exported in the `jsonrpc` module for consumption. 2. A private `handle_request()` function which takes an incoming `ServerRequest` and triggers the corresponding handler method on the user's `LanguageServer` implementation. It also contains basic checks for initialization and shutdown previously stored in `Delegate`. `<LspService as Service>::call()` has been refactored to reference `generated_impl::handle_request()` internally, and `LspService` has been redefined as `fn(jsonrpc::Incoming) -> Option<jsonrpc::Outgoing>`. Also, `Arc<dyn LanguageServer>` is now considered valid as a side effect of this work. The existing `delegate` module has been removed, and some tests had to be tweaked to get everything to pass. One small hiccup was found with `service::tests::exit_notification` test, where this notification would no longer parse: ```json {"jsonrpc":"2.0","method":"initialized"} ``` It seems that `jsonrpc-core` parses the JSON more permissively, despite the LSP spec technically defining the `initialized` notification as: ```json {"jsonrpc":"2.0","method":"initialized","params":{}} ``` AFAIK, this increased strictness shouldn't pose a problem, as `coc.nvim` and several other popular language client seem to send the correct form of the notification, but it's notable nonetheless as a potential caveat.
- Loading branch information
1 parent
1be5882
commit 07c0e6c
Showing
9 changed files
with
649 additions
and
508 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.