Anyone know how rust-analyzer decides what to show automatically even if a module isn't in scope e.g., "extension methods" from a trait not in scope that a type in scope implements? For example, I defined a Headers
type in a module, and in the same module defined a HeadersExt
that adds some helpful methods we don't always want in scope (not relevant for most use cases). These do show up automatically in VSCode's completion list a la rust-analyzer.
Meanwhile, I have a trait named ClientBuilder
in another crate implemented a type (e.g. name) SubClientBuilder
but if ClientBuilder
isn't in scope, I don't see the implemented methods.
In both cases, the types are defined in a "core" crate with no prelude and I tried exporting both from the crate root to no avail.
In the HeadersExt
case, rust-analyzer shows "ext_fn() (use core::HeadersExt)" and, sure enough, if I select it core::HeadersExt
is added to the imports. That doesn't happen with the ClientBuilders
trait's methods.
The only difference is that ClientBuilders
has 1 method with no default implementation, and a few that do have default implementations. HeadersExt
defines default implementations for all methods.
I would really like the same dev experience for ClientBuilders
(which I also tried adding "Ext" to just in case it was a naming convention light-up). So how does rust-analyzer decide when to show "extension methods" and add imports as needed?
Some relevant code:
HeadersExt
: https://github.com/heaths/azure-sdk-for-rust-proto/pull/9/commits/949f4f3a1d010bff1df17e372effeefccee6744e#diff-d4c9a15258bfd0250990fde1ac4fd07a964d4a26cc4936a5d3ba4c840bda9a20R263ClientBuilders
: https://github.com/heaths/azure-sdk-for-rust-proto/blob/a2ccf7ba4ff8398fcc30923ebe96ce4fa43710e5/sdk/core/src/options/mod.rs#L51- Impl: https://github.com/heaths/azure-sdk-for-rust-proto/blob/a2ccf7ba4ff8398fcc30923ebe96ce4fa43710e5/sdk/client_builder_method_builder/src/lib.rs#L73
- Use: https://github.com/heaths/azure-sdk-for-rust-proto/blob/a2ccf7ba4ff8398fcc30923ebe96ce4fa43710e5/sdk/client_builder_method_builder/examples/set_secret_client_builder.rs#L13