nvim-rs icon indicating copy to clipboard operation
nvim-rs copied to clipboard

Hide Value from user and use serde instead

Open oberblastmeister opened this issue 3 years ago • 8 comments

In your thoughts that you posted I saw that you wanted a strongly typed api and to hide Value from the user. I have implemented that using rmp_serde and the with_serde feature flag of rmpv. This allows send_msg to send anything with args that implement Serialize opening up possibilities for a strongly typed api because using structs as args will also work. This way call and call_function can both take a wide range of values also. The base of this pr is implementing Serialize and Deserialize for RpcMessage. Before you were manually serializing and deserializing into RpcMessage. Instead I have implemented the serde traits which is much easier and fits into the serde data model. Eventually I think that we don't need Value at all and can just rely on serde. This pr can open up very cool possibilities like having custom structs for common things like CompleteItems and QfListItems.

Licensing: The code contributed to nvim-rs is licensed under the MIT or Apache license as given in the project root directory.

oberblastmeister avatar Feb 15 '21 19:02 oberblastmeister

Hey sorry for leaving this open so long, I have a hard time finding time for this project. I think I can work at it again real soon, but first I'll need to do chores I guess (CI...), so it might still need some time. Especially seeing this is somewhat complicated for me :)

I'm a bit hesitating anyways, since it adds serde as a dependency, and I'm not yet sure if that's really pulling it's weight. But that strongly typed API and custom structs really are enticing!

KillTheMule avatar Jun 01 '21 19:06 KillTheMule

Its okay, I was working on a larger pr after I submitted this one by I lost interest. However, I do think it is very nice because then all functions can take a serde trait bound allowing for very expressive calling of functions.

oberblastmeister avatar Jun 01 '21 22:06 oberblastmeister

So I'll be putting in some inline questions for @smolck who wants to take over here.

KillTheMule avatar Oct 06 '21 20:10 KillTheMule

Maybe it would be far simpler to abstract Value to impl Into<Value>. If Value is provided it will be no-op anyways.

kkharji avatar Apr 27 '22 16:04 kkharji

That might just be feasible as well :)

KillTheMule avatar Apr 27 '22 17:04 KillTheMule

That might just be feasible as well :)

So I tried to manually do it then realized the code is generated, in generated code, I have gotten away with code_data: code_data.into() but for the rest I couldn't understand how to do it with the template

kkharji avatar Apr 27 '22 17:04 kkharji

Not all is generated, have a look at https://github.com/KillTheMule/nvim-rs/blob/master/src/neovim_api_manual.rs. If we figure out something good, changing the generating script can follow.

KillTheMule avatar Apr 28 '22 07:04 KillTheMule

This branch has conflicts that must be resolved

micwoj92 avatar Jul 16 '22 00:07 micwoj92