rust-tools.nvim icon indicating copy to clipboard operation
rust-tools.nvim copied to clipboard

RustHoverActions doesn't work for async main functions and tests

Open poljar opened this issue 2 years ago • 4 comments

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:

image

However, RustHoverActions doesn't display anything sensible:

image

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:

image

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"] }

poljar avatar Aug 31 '22 14:08 poljar

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

ten3roberts avatar Nov 15 '22 10:11 ten3roberts

Same here :/

ls-devs avatar Dec 10 '22 02:12 ls-devs

same here :( the hover does not show the options to debug/run the app if main is async

Masber avatar Feb 27 '23 08:02 Masber

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

orzen avatar Jul 21 '23 20:07 orzen