Use `emit_analysis` data to complete certain files
Zig has a fantastic build feature called emit_analysis which well... emits analysis type data from the compiler proper.
We do not use emit_analysis data in zls because it only appears upon valid compilation, which is quite frustrating for people working on code that is not in a compilable state and kind of defeats the purpose of zls (and we'll probably never use compiler output directly for this reason :( ). The major pro of this data though is that it's nearly perfect and accounts for comptime, which is fantastic.
Here's an idea: use emit_analysis data to provide analysis data on "static" files that only need to compile once and "never" change; the perfect two candidates that come to mind are:
@cImported code; it doesn't change unless you update the C headers/code or the@cImportblock; this would help solve #366 for some cases (using a cache inspection hack and using traditional analysis would be valid while code isn't in a compilable state)- Zig libraries (being used)
There are quite a few complex factors to this: how do we achieve reasonable performance, how do we cache bust our emit_analysis data, how do we store the data (LSIF isn't enough), but I'm sure we can crack it together! <3
Also, emit_analysis is per compilation unit and not per-file, so isolating results for just a certain C import for example without relying on valid compilation of the file using that @cImport is possible, just complex.
Idea: modify the build runner to create a build unit just with the specific @cImport with emit_analysis set to .emit; then (in theory) we get completions for the cImport even without valid whole project compilation, which would be a best case scenario for this! (Same idea could apply to libraries!)
Hello. Can we use zig translate-c tool to autocomplete @cImport directives?
For the time being, yes! Probably more well suited for #366, so I'll comment there.