Closed IWANABETHATGUY closed 2 years ago
I suspect this branch will land in mainline sometime by the end of this week. I'm trying to find some time in the evenings after work to review all the open PRs, address feedback, and merge them in the correct order. Once everything is merged, along with any follow-up PRs, I'll update the changelog and draft a new release shortly thereafter.
As an aside, the Backend::test
custom request handler written in your repo (source) can be rewritten in a simpler way:
- async fn test(&self, params: serde_json::Value) -> Result<Vec<(usize, usize, String)>> {
+ async fn test(&self, params: InlayHintParams) -> Result<Vec<(usize, usize, String)>> {
let mut hashmap = HashMap::new();
- if let Ok(InlayHintParams { path }) = serde_json::from_value::<InlayHintParams>(params) {
- if let Some(ast) = self.ast_map.get(&path) {
- ast.iter().for_each(|(k, v)| {
- type_inference(&v.body, &mut hashmap);
- });
- }
- }
+ if let Some(ast) = self.ast_map.get(¶ms.path) {
+ ast.iter().for_each(|(k, v)| {
+ type_inference(&v.body, &mut hashmap);
+ });
+ }
The LspServiceBuilder::method()
method may accept any params
type which implements serde::Deserialize
. Similarly, handlers may also return any jsonrpc::Result<T>
where T
implements serde::Serialize
.
I think #313 should be updated to include clearer documentation on how to define custom requests, to make this fact more obvious.
As an aside, the
Backend::test
custom request handler written in your repo (source) can be rewritten in a simpler way:- async fn test(&self, params: serde_json::Value) -> Result<Vec<(usize, usize, String)>> { + async fn test(&self, params: InlayHintParams) -> Result<Vec<(usize, usize, String)>> { let mut hashmap = HashMap::new(); - if let Ok(InlayHintParams { path }) = serde_json::from_value::<InlayHintParams>(params) { - if let Some(ast) = self.ast_map.get(&path) { - ast.iter().for_each(|(k, v)| { - type_inference(&v.body, &mut hashmap); - }); - } - } + if let Some(ast) = self.ast_map.get(¶ms.path) { + ast.iter().for_each(|(k, v)| { + type_inference(&v.body, &mut hashmap); + }); + }
The
LspServiceBuilder::method()
method may accept anyparams
type which implementsserde::Deserialize
. Similarly, handlers may also return anyjsonrpc::Result<T>
whereT
implementsserde::Serialize
.I think #313 should be updated to include clearer documentation on how to define custom requests, to make this fact more obvious.
Thanks!
357e062
I see, the documentation is very helpful, thanks.
It's time to close this issue, since the branch has been merged.
I wrote a tower-lsp boilerplate template https://github.com/IWANABETHATGUY/tower-lsp-boilerplate, which have implemented some common language features. The issue is that i used the custom request that has not been landed yet, so I am wonder when this
support-custom-server-requests
branch would be merged.