VSCode rust-analyzer code completion in doctest not working

I'm writing some trivial doctest for my crate. I found within the doctest section although syntax highlighting works, it can't code complete for any symbol. e.g. x or assert_eq!

/// Some documentation
/// # Example
/// ```
/// let x = 42;
/// assert_eq!(42, x);
/// ```

My issue is that while authoring the doctest I expect VSCode to auto-complete as I type just like when I write a function body.

I searched on the forum before creating this topic and found no related story. I wonder if people use different setup. IMO, this is a reasonable ask...

There is no problem with the document annotation code, you can view the test document through the command

cargo doc -open

Your file must be lib.rs , vscode will be displayed Run Doctest

Thanks for looking into this! cargo d --open works. My issue is that while authoring the doctest I expect VSCode to auto-complete while I type just like when I write a function body. Hope it clarifies.

rust-analyzer doesn't auto-complete doctests. I don't know if it can be supported, but it hasn't been implemented.

1 Like

RA issue 4170.

Ty! That's exactly what I'm looking for.