Hello I would like to write a tool which parses a rust crate and generates metadata about fn/structs etc.. This should include the places they are used and at the place of their use I'd need to figure out where they were defined. So I basically would like an iterator over all items in a file and get their source location/ comments/ type/ metadata if applicable or else get where they are used. I think using rust analyzer this should be fairly easy and would make things like "go to definition" on sourcehut possible https://drewdevault.com/2019/07/08/Announcing-annotations-for-sourcehut.html . I tried the ra_ide crate and ra_syntax crate but could not quite find the right part of the API. As far as I can see my use case is a bit unusual for RA because its kind of greedy whereas RA is more lazy/ on demand so if its not really supported API that would be a helpful answer as well. Thanks!
AFAIK you should look at ra_hir, it provides name resolution, type inference and so on.
So what I think I can do is something along the lines of using ra_syntax to iterate over all tokens or some other nodes of the tree and for the ones that are interesting (like e.g. function, struct definitions and uses) invoke ra_ide to get the information for that position in the file but maybe there is an existing iterator-like thing I'm missing that would make this easier.
For ha_hir I was not sure how to deal with the databases/ construct them/ there are a few of them. My approach was whenever I saw some struct I wanted to use, search where it was returned and this did not yield the information I wanted in these cases.
Using ra_syntax and ra_ide in that way is probably the right approach
you could also take a look at the syntax highlighting code (
syntax_highlighting.rs) for an example of something similar
analysis_stats.rs for an example of doing semantic analysis on a crate, but you're probably better off with the IDE level abstractions unless you want to do something special that they don't provide
you get a database by calling
raw_database() on an