rust-tools.nvim
rust-tools.nvim copied to clipboard
RustHoverActions doesn't work for async main functions and tests
Tokio, and other async runtimes, tend to have nice macros to use async functions as a main function or as a test. Async functions annotated with #[tokio::main]
and #[tokio::test]
can be used normally as the main function, and test functions respectively, without any additional setup.
Those functions can be run and debugged with the vim.lsp.codelens.refresh()
and vim.lsp.codelens.run()
lua methods just fine:
However, RustHoverActions
doesn't display anything sensible:
RustHoverActions
works fine if we convert the method back to a non-async one and do the async plumbing #[tokio::main]
does for us manually:
The minimal reproducer is:
use std::time::Duration;
#[tokio::main]
async fn main() {
println!("Sleeping, world!");
tokio::time::sleep(Duration::from_secs(10)).await;
println!("Hello, world!");
}
While the working non-async variant is:
use std::time::Duration;
fn main() -> anyhow::Result<()> {
let runtime = tokio::runtime::Runtime::new()?;
runtime.block_on(async {
println!("Sleeping, world!");
tokio::time::sleep(Duration::from_secs(10)).await;
println!("Hello, world!");
});
Ok(())
}
Both work with the following Cargo.toml
file:
[package]
name = "test-tokio-rust-tools"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1"
tokio = { version = "1.20.1", features = ["rt-multi-thread", "macros", "time"] }
I am also still having this problem. Does not show up on hover K
on tokio::main, or log::test
function, but they do show up in Runnables
Same here :/
same here :( the hover does not show the options to debug/run the app if main is async
I also encounter this issue with tokio::main
. Would be nice if someone could comment and give feedback if I am doing something wrong?
Thanks in advance