Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support #[doc = include_str!(...)] in hover documentation #11137

Open
Tracked by #86
MaulingMonkey opened this issue Dec 28, 2021 · 5 comments
Open
Tracked by #86

Support #[doc = include_str!(...)] in hover documentation #11137

MaulingMonkey opened this issue Dec 28, 2021 · 5 comments
Labels
A-hover hover feature A-macro macro expansion C-enhancement Category: enhancement

Comments

@MaulingMonkey
Copy link

It'd be nice if external documentation could show up in hover tooltips

#[doc = include_str!("MyThing.md")] // doesn't work
#[doc = "this works fine already" ]
struct MyThing;

#[doc = include_str!(...)] attributes are currently thrown away here:
https://github.com/rust-analyzer/rust-analyzer/blob/355a4bdb883ee9edc1c32b553fcf91c302b3df19/crates/hir_def/src/attr.rs#L696-L707

Hacking together a new branch is easy enough:

        } else if let Some(ast::Expr::MacroCall(call)) = ast.expr() {
            if call.path()?.segment()?.name_ref()?.text() == "include_str" {
                Some(Interned::new(AttrInput::Literal(SmolStr::new(format!("include_str!(...): {:?}", call)))))
            } else {
                None
            }

But I'm having difficulty figuring out how to plumb my way into hir_expand::builtin_fn_macro::include_str_expand, or to figure out the path of the current AST, or figuring out if this is even the right place to be handling this.

@bjorn3
Copy link
Member

bjorn3 commented Dec 28, 2021

Just checking the name is not enough. A different macro called include_str!() can shadow it I think. You can also re-export it with a different name. There probably is some logic for other builtin macros you can use.

@Veykril
Copy link
Member

Veykril commented Dec 28, 2021

cc #8092

@lnicola
Copy link
Member

lnicola commented Dec 29, 2021

We'll also have trouble finding the file, right? CC #10178

@ModProg
Copy link
Contributor

ModProg commented May 27, 2022

Another addition here, I'm generating some documentation using concat! in a macro. It is probably thrown away for the same reason.

@MasterTemple
Copy link

I have created the lsp_doc crate that provides a workaround for the LSP hover/preview, and it is compatible with the cargo doc output.

Installation

cargo add lsp_doc

Usage

/// Here is a table:
#[lsp_doc("table.md")]
/// Here is some long piece of text:
#[lsp_doc("lorem.md")]
fn anything() {}

Neovim

VSCode

Hope that helps in the mean time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-hover hover feature A-macro macro expansion C-enhancement Category: enhancement
Projects
None yet
Development

No branches or pull requests

6 participants