Stream: t-compiler/wg-rls-2.0

Topic: RA tree of dependencies visible symbols


Robert Sedlacek (Sep 21 2019 at 15:25, on Zulip):

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.

Daniel Mcnab (Sep 21 2019 at 15:27, on Zulip):

Collect_deps in hir might have what you want

Robert Sedlacek (Sep 21 2019 at 15:30, on Zulip):

Hm, I can't seem to find that one in the repository

Daniel Mcnab (Sep 21 2019 at 15:36, on Zulip):

Actually, maybe you should trace completion from a crate root

Daniel Mcnab (Sep 21 2019 at 15:36, on Zulip):

Completion is somewhat similar to documentation in its requirements

Robert Sedlacek (Sep 21 2019 at 15:37, on Zulip):

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.

Robert Sedlacek (Sep 21 2019 at 15:37, on Zulip):

That's a good starting point, thanks :)

matklad (Sep 21 2019 at 16:11, on Zulip):

@Robert Sedlacek that should be possible yeah, but, as usual, keep in mind that rust-analyzer is pretty incomplete

matklad (Sep 21 2019 at 16:12, on Zulip):

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

matklad (Sep 21 2019 at 16:12, on Zulip):

note that we don't handle visibility yet

Robert Sedlacek (Sep 21 2019 at 16:14, on Zulip):

Does that take reexports into consideration as well?

Robert Sedlacek (Sep 21 2019 at 16:14, on Zulip):

Ah, probably not. I actually used that code as template for my experiments :)

matklad (Sep 21 2019 at 16:18, on Zulip):

@Robert Sedlacek .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 .

Robert Sedlacek (Sep 21 2019 at 16:19, on Zulip):

@matklad Aah, thank you, I'll check that out

matklad (Sep 21 2019 at 16:22, on Zulip):

Note that I think we don't handle visibility yet at all, and that might be a bigger problem.

matklad (Sep 21 2019 at 16:23, on Zulip):

It shouldn't be hard to provide visbility info. INtegrating it correctly with name resolution would be harder, but not insurmontable.

Robert Sedlacek (Sep 21 2019 at 16:26, on Zulip):

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.

Laurențiu Nicola (Sep 22 2019 at 18:19, on Zulip):

just to make sure, have you seen https://github.com/rust-dev-tools/cargo-src?

Robert Sedlacek (Sep 22 2019 at 20:12, on Zulip):

@Laurențiu Nicola I haven't seen that one yet, thanks!

Last update: Nov 19 2019 at 18:25UTC