Stream: t-compiler/rust-analyzer

Topic: collecting RA data into postgres


Riccardo D'Ambrosio (Feb 03 2021 at 19:07, on Zulip):

Hello!

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_hir and ra_ap_ide but i am a bit confused on:

Florian Diebold (Feb 03 2021 at 19:12, on Zulip):

you probably mostly want the API of the hir crate. The code of the analysis-stats command should give some pointers

Riccardo D'Ambrosio (Feb 03 2021 at 19:13, on Zulip):

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

Riccardo D'Ambrosio (Feb 03 2021 at 20:04, on Zulip):

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?

Jonas Schievink [he/him] (Feb 03 2021 at 20:06, on Zulip):

That would require everything stored in it to be serializable

Jonas Schievink [he/him] (Feb 03 2021 at 20:06, on Zulip):

I don't think it's really supported by salsa either

Riccardo D'Ambrosio (Feb 03 2021 at 20:07, on Zulip):

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

Florian Diebold (Feb 03 2021 at 20:07, on Zulip):

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

Riccardo D'Ambrosio (Feb 03 2021 at 20:08, on Zulip):

oh right :laughing:

Florian Diebold (Feb 03 2021 at 20:10, on Zulip):

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

Riccardo D'Ambrosio (Feb 03 2021 at 20:12, on Zulip):

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?

detrumi (Feb 03 2021 at 21:09, on Zulip):

analysis-stats already loops over items, so you can pattern match all the way down

Riccardo D'Ambrosio (Feb 03 2021 at 21:15, on Zulip):

Yeah getting items seems super easy, but i cant find a way of getting defined variables :/

Jonas Schievink [he/him] (Feb 03 2021 at 21:18, on Zulip):

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

Riccardo D'Ambrosio (Feb 03 2021 at 21:19, on Zulip):

isnt this only for functions, statics, and consts?

Riccardo D'Ambrosio (Feb 03 2021 at 21:20, on Zulip):

Oh i see what you mean

Last update: Jul 24 2021 at 20:15UTC