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

Docs. on hover for cfg_attr' #18444

Open
blyxyas opened this issue Oct 30, 2024 · 10 comments
Open

Docs. on hover for cfg_attr' #18444

blyxyas opened this issue Oct 30, 2024 · 10 comments
Labels
A-hover hover feature A-macro macro expansion C-feature Category: feature request

Comments

@blyxyas
Copy link
Member

blyxyas commented Oct 30, 2024

Example:

#[doc = include_str!(...)]

The code fragment above will display documentation on hover when the user hovers over doc, and over include_str. Both with their respective documentation.

If the user instead uses #[cfg_attr(doc, doc = include_str!(...))], which reduces compilation time, no documentation will be shown for doc or include_str.

It would be excellent if we could treat the second meta item in the metalist for cfg_attr as it's own attribute (because it is)

@blyxyas blyxyas added the C-feature Category: feature request label Oct 30, 2024
@blyxyas
Copy link
Member Author

blyxyas commented Oct 30, 2024

@rustbot label: +A-hover

@rustbot rustbot added the A-hover hover feature label Oct 30, 2024
@ChayimFriedman2
Copy link
Contributor

I think we do evaluate cfg_attrs here, but we don't set cfg(doc). You can try adding it to rust-analyzer.cargo.cfgs.

@blyxyas
Copy link
Member Author

blyxyas commented Oct 30, 2024

How do I add it? I've tried setting it to {"doc": true}, {"doc": "true"}, {"doc": {}} and ["doc"] but no hover hints on the attribute appear after a server restart.

@ChayimFriedman2
Copy link
Contributor

Oh we do evaluate cfgs, but even if you set cfg(doc) we don't currently support doc = include_str!(), even when it's not under cfg. I believe there is an issue about that.

@lnicola
Copy link
Member

lnicola commented Oct 30, 2024

#11137

@ChayimFriedman2 ChayimFriedman2 added the A-doc-comments doc string related issues label Oct 30, 2024
@lnicola
Copy link
Member

lnicola commented Oct 30, 2024

I wanted to close this, but we don't support code that's gated for a different platform, so it might actually be a good idea to enable cfg(doc) by default.

@lnicola lnicola added A-project-model project model and workspace related issues A-doc-comments doc string related issues and removed A-doc-comments doc string related issues labels Oct 30, 2024
@ChayimFriedman2 ChayimFriedman2 added the A-macro macro expansion label Oct 30, 2024
@ChayimFriedman2
Copy link
Contributor

I'm not sure we should enable cfg(doc). People use it, e.g. to show documentation even of the non-current platform, and it may cause wrong diagnostics to be emitted if we enable it. IMO we should leave it to users who want it to enable it themselves.

@lnicola lnicola added A-cargo cargo related issues and removed A-macro macro expansion A-cargo cargo related issues labels Oct 30, 2024
@rust-lang rust-lang deleted a comment from ChayimFriedman2 Oct 30, 2024
@blyxyas
Copy link
Member Author

blyxyas commented Oct 30, 2024

There seems to be a misunderstandment:

When I hover over the include_str macro, I get some documentation from std::macros::builtin.
The same, when I hover over doc in #[doc = ...] I get the following:

#[doc]
Valid forms are:

#[doc(hidden|inline|...)]
#[doc = string]

That's what's lost with cfg_attr.

@ChayimFriedman2 ChayimFriedman2 added A-macro macro expansion and removed A-doc-comments doc string related issues A-project-model project model and workspace related issues labels Oct 30, 2024
@ChayimFriedman2
Copy link
Contributor

Ah that's indeed a different thing, and it isn't unique to doc, it's the same with all attributes that have hover info.

@GuillaumeGomez
Copy link
Member

Enabling cfg(doc) by default doesn't sound like a good idea. In some crates (like std), the items generated for docs are not the actual implementations. Just a trick to give information whatever the platform.

Would it be possible to just expand cfg_attr(doc, doc = ...) in any case?

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-feature Category: feature request
Projects
None yet
Development

No branches or pull requests

5 participants