zigtools / zls

A Zig language server supporting Zig developers with features like autocomplete and goto definition
MIT License
2.78k stars 280 forks source link

auto-import #74

Open ghost opened 4 years ago

ghost commented 4 years ago

i'm not really sure if this is even possible with the lsp, but it would be cool if one could have this feature like you have it for e.g. java example: you type page_all<Tab> in your main function, but you don't have std.heap.page_allocator imported then it suggests to add a import at the top which it does automatically when selection that completion

pmwhite commented 4 years ago

Not as automatic, but perhaps more in line with LSP, the server could provide code actions that import an undefined variable. That is, if page_allocator is typed somewhere, but there is nothing by that name in scope, then a code action would be provided that could add a the line

const page_allocator = @import("std").heap.page_allocator;

to the top of the file.

SuperAuguste commented 1 year ago

Upon reflection, this isn't really possible in a computationally effective way because it would require us to actively juggle every single declaration in std anytime anybody types something. Feel free to drop any implementation ideas here though, but I'm closing this as not planned for now.