erlang_ls
erlang_ls copied to clipboard
Improve variable completion
Is your feature request related to a problem? Please describe.
-
The code completion displays the variables of all functions
-
When the function is imcomplete, the variables in the function are not displayed.
Describe the solution you'd like 5b79826d1a31679f972b445bd8ef2491e283b635 In this branch, I try to save all atoms and variables, and also limiting the scope of variables. The problem is, I don't know if this will cause other bug.
Final effect
Hi! I have two main questions about this approach:
- What's the memory impact for this? For big projects, this could be significant. If I remember correctly, we were storing variables and atoms before and then we removed them.
- Are we sure we don't want completions from other functions? It is very common for me to reuse the same variable name across functions in the same module and having automatic completion in those cases can be useful.
We do store variables and atoms from parsable forms. The proposed commit only adds more data for unparsable forms, so I don't think this causes noticable difference for any project size. I am not sure about atoms but I very much welcome parsing variables in incomplete code.
I am not sure about completion scope (don't have a strong opinion)
- I often use the editor's non-lsp word completion to complete variables (because of the issue described in this ticket) but that is not aware of Erlang scoping. lsp has the advantage of knowing function range, so one way could be to use lsp completion for variables within the same function and simple word-completion for all variables in the file or project
- find variable references already works on function clause range so this would be consistent with that (but ofc completion is a different thing)
@gomoripeti You are indeed right. For some reason I thought we were treating variables separately from the usual list of POIs, but we are not. And it looks like we treat atoms in the same way. So, sorry about the misleading comment.
Dealing with incomplete code is also one thing that I'm interested, too, since that's where developers spend most of their time on when writing code and having completion and other features there would be a game changer. I wonder what's the best way to achieve that. For example, it would be great to be able to navigate to function calls even if the function is incomplete. But maybe we should keep that discussion separate from this.
Regarding completion scope, it would be good to know how different editors handle it, to see if what you suggest is a viable option.
Regarding variable completion scope it seems like there are different preferences in the community. How about making that configurable?
Regarding variable completion scope it seems like there are different preferences in the community. How about making that configurable?
I think so too.