rust-lang / rust-lang/rust-analyzer
Do not auto-complete `#[doc(hidden)] #[macro_export]` item after `crate::|`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
When you are inside of a crate, rust-analyzer suggests its #[doc(hidden)]. For example, here Item will be in the list of suggestions at the cursor |:
#[doc(hidden)]
struct Item;
type Alias = crate::|;
I'm making the case that if such an item is a macro marked #[macro_export] and #[doc(hidden)], it should not be present in the list of suggestions.
This is because in Rust, you cannot export a macro_rules! item from a crate without also exporting it at the crate level. There is a common hack for this:
pub mod nested_macro {
#[macro_export]
#[doc(hidden)]
macro_rules! __macr { () => {}; }
#[doc(inline)]
pub use __macr as macr;
}
This pretends that the macro is from a nested module. It will render like so in rustdoc, the name macr won't be available at crate root (but __macr will be).
This lets users use your_crate::nested_macro::macr, with your_crate::macr being a hidden item. The problem here, is that rust-analyzer will suggest __macr even though this hack is used.
use crate::|;
At |, __macr will be suggested.
My personal problem
My crate, derive-aliases allows users to create aliases for derives. Like #[derive(..Copy)] expanding to #[derive(Copy, Clone)]:
mod derive_alias {
// Define the aliases
derive_aliases::define! {
Eq = ::core::cmp::PartialEq, ::core::cmp::Eq;
Ord = ..Eq, ::core::cmp::PartialOrd, ::core::cmp::Ord;
Copy = ::core::marker::Copy, ::core::clone::Clone;
}
}
use derive_aliases::derive;
// Use the aliases:
#[derive(Debug, ..Ord, ..Copy)]
struct User;
As an implemetation detail, what that define! really does is expand into macro_rules! items:
mod derive_alias {
macro_rules! Eq {}
pub(crate) use Eq;
macro_rules! Ord {}
pub(crate) use Ord;
macro_rules! Copy {}
pub(crate) use Copy;
}
This works at the crate-level. However, users should be able to define aliases in 1 crate, and use in another (for use in workspaces, for example). In order to do this, each generated macro_rules! item needs #[macro_export] applied to it.
Users may have dozens+ of aliases. When they add the #![export_derive_aliases] inside the macro, each macro gets #[macro_export] applied to it. And then when they have use crate::|, they get suggested their dozens of derive aliases at the crate level, which is very confusing - because again, the fact that this macro expands to macro_rules! items is an implementation detail
Marking these macros #[doc(hidden)] should make it not show up in the crate::| suggestion
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the completion behavior from the issue's Rust examples, especially suggestions after crate::| for #[doc(hidden)] #[macro_export] macros. Trace the crate-level completion path and its handling of hidden exported macros. Done means the hidden implementation macros no longer appear in these suggestions while the intended public alias remains usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- developer-experience, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100