Skip to content

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

@MaulingMonkey

Description

@MaulingMonkey

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions