feat(lsp): commands - #1304
Conversation
| tokio::spawn(async move { | ||
| language_server.command(command).await | ||
| }); |
There was a problem hiding this comment.
The problem you're seeing is because you're trying to move language_server into the async closure.
This should work:
| tokio::spawn(async move { | |
| language_server.command(command).await | |
| }); | |
| let future = language_server.command(command); | |
| tokio::spawn(async move { | |
| future.await | |
| // TODO: log the result here | |
| }); |
There was a problem hiding this comment.
Tried that before, this moves the lifetime issue to
error[E0621]: explicit lifetime required in the type of `cx`
--> helix-term/src/commands.rs:3268:30
|
3268 | let picker = Picker::new(
| ^^^^^^^^^^^ lifetime `'static` required
There was a problem hiding this comment.
Right, you're also reusing the language_server from outside the cx.callback, and the compiler can't know how long the callback will live for. So it expects language_server -> doc -> cx to live for static.
To avoid this you need to re-fetch the doc/language_server inside the callback, easiest way to do that is let (doc, _view) = current!(editor), the most correct would be to let doc_id = doc.id() before cx.callback, then re-fetch that exact ID in the closure
There was a problem hiding this comment.
Thanks a lot for the help! Fixed now. I also extracted the command execution into separate function so it can be re-used so it can be re-used between commands, code actions, and possibly code lenses in the future.
|
|
||
| /// Reply to a language server RPC call. | ||
| pub fn reply( | ||
| pub fn reply<R>( |
There was a problem hiding this comment.
There's a reason the method did not use generics: due to monomorphization it can lead to code bloat since the method is big. The way to fix this would be to rename the old function as reply_impl, then define a new reply function that uses generics and calls reply_impl.
See the example here under "inlining in practice" (under "fifth,") https://matklad.github.io/2021/07/09/inline-in-rust.html
There was a problem hiding this comment.
Wow, didn't realize the implications, thanks a lot. I just reverted the changes for now. If it isn't good enough I can introduce reply and reply_impl.
|
@archseer sorry, forgot to run clippy, the lint issue should be fixed now. |
This is work in progress PR that implements LSP commands. Usable for example for code actions and code lens.
Fixes: #1299
Related: #183