zls icon indicating copy to clipboard operation
zls copied to clipboard

auto-import

Open ghost opened this issue 5 years ago • 3 comments

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

ghost avatar May 23 '20 15:05 ghost

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.

pmwhite avatar May 28 '20 17:05 pmwhite

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.

SuperAuguste avatar Oct 26 '22 03:10 SuperAuguste