Hey everyone, hope I'm in the right place here for a RA question :)
I'm experimenting with RA trying to see if it's possible to make a CLI API/documentation browser. I'm currently wondering if there's a good way to get a tree of a (dependency) crates' publicly visible symbols and the names they are available as. Only played with things I got via
ra_batch::load_cargo at the moment so I assumed I'm probably just missing knowledge of some parts.
Collect_deps in hir might have what you want
Hm, I can't seem to find that one in the repository
Actually, maybe you should trace completion from a crate root
Completion is somewhat similar to documentation in its requirements
You mean doing a completion run and just collect whatever it scans? Hadn't considered that, but yeah, it would need all the right mechanics anyway.
That's a good starting point, thanks :)
@Robert Sedlacek that should be possible yeah, but, as usual, keep in mind that rust-analyzer is pretty incomplete
We have code that walks module declarations here: https://github.com/rust-analyzer/rust-analyzer/blob/468e1d14c1a4b3d646207ae919082dc17753cd31/crates/ra_cli/src/analysis_stats.rs#L40-L45
note that we don't handle visibility yet
Does that take reexports into consideration as well?
Ah, probably not. I actually used that code as template for my experiments :)
.declatations is only for directly declared items. However, the info about reexports is there, it's just not exposed by this particular method. See the source code for
declarations method (in
code_model.rs), it explicitelly filters-out imported items .
@matklad Aah, thank you, I'll check that out
Note that I think we don't handle visibility yet at all, and that might be a bigger problem.
It shouldn't be hard to provide visbility info. INtegrating it correctly with name resolution would be harder, but not insurmontable.
Yeah, I'm probably still a bit too unfamiliar with the codebase for that one :) Though maybe I'll be closer when I tried out more now that I know about the reexports.
just to make sure, have you seen https://github.com/rust-dev-tools/cargo-src?
@Laurențiu Nicola I haven't seen that one yet, thanks!