I was recently looking at https://source.chromium.org/ and i thought it would be cool to have a rust version of something like that, i wanted to experiment just for fun. However, i am not quite sure how i would go about loading a crate from the file system with RA and then getting info like variables, modules, structs, etc from it. What structures/crates should i use? i look at
ra_ap_ide but i am a bit confused on:
you probably mostly want the API of the hir crate. The code of the analysis-stats command should give some pointers
Cool, ill look through that. I looked through hir already but was a bit confused on how to get the data that the ide crate gets. I think looking at the ide crate source code should help
Since RA keeps a DB of basically everything is it possible to just serialize that entire db then load it back at a later date? or would that be way too much info to store efficiently?
That would require everything stored in it to be serializable
I don't think it's really supported by salsa either
I see, because to do this i need to keep a database of things like every variable in a file, its type, its definition location, etc
RA doesn't really keep a full database of all that information. it's lazily computed, so you've got to ask for it before it's in the DB
oh right :laughing:
theoretically it should be possible to store and reload the DB to reduce startup times; that's how rustc incremental compilation works. as Jonas wrote, it'd require everything to be serializable and salsa support though
I see, then i think ill just do it the brute force way and have a program to call RA and load the data into postgres. How would i go about crawling every file and getting stuff like the variables in there, etc?
analysis-stats already loops over items, so you can pattern match all the way down
Yeah getting items seems super easy, but i cant find a way of getting defined variables :/
it's a bit obscure, but maybe this
From impl helps? https://rust-analyzer.github.io/rust-analyzer/hir/struct.Local.html#impl-From%3C(DefWithBodyId%2C%20Idx%3CPat%3E)%3E
isnt this only for functions, statics, and consts?
Oh i see what you mean