zls icon indicating copy to clipboard operation
zls copied to clipboard

Use `emit_analysis` data to complete certain files

Open SuperAuguste opened this issue 3 years ago • 3 comments

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:

  1. @cImported code; it doesn't change unless you update the C headers/code or the @cImport block; 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)
  2. 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

SuperAuguste avatar Jul 18 '22 13:07 SuperAuguste

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!)

SuperAuguste avatar Jul 18 '22 13:07 SuperAuguste

Hello. Can we use zig translate-c tool to autocomplete @cImport directives?

star-tek-mb avatar Jul 20 '22 16:07 star-tek-mb

For the time being, yes! Probably more well suited for #366, so I'll comment there.

SuperAuguste avatar Jul 20 '22 17:07 SuperAuguste