Pasting my Reddit comment here:
let's say that given a crate's source code, I want to create a data structure containing type signatures of all functions with proper naming, trait/lifetime constraints, post proc macro-expansion. I do not care about codegen (so being able to avoid it would a big plus).
What would be the best way of doing so? (Best = if there is some change in the compiler/cargo, I get the change soon).
I got a suggestion that I should use this crate. Looking at the source code here/in rls
, I can't really tell what is going on :(. For example, if I have
let host = AnalysisHost::new(Target::Debug);
let p = Path::new("/home/theindigamer/Code/rls-analysis");
// Not entirely sure what the second path should be
host.reload(p, Path::new("."));
println!("Roots: {:?}", host.def_roots());
I'd naively expect that I'll get the ids of rls-analysis
crate and its dependencies (transitively), and then I can call for_each_child_def
to recursively traverse all the modules in a crate. Instead I get an empty vector, so it seems like nothing has been analyzed yet. Am I vaguely on the right track or way off the mark?
The other option I'm exploring is using syn
to parse stuff (which is working ok) and implement the module traversal/Cargo.toml
parsing myself.
I understand that writing a long explanation might be too much work and you may not have the time; in that case, a pointer to roughly the right place(s) in the code would still be appreciated.