erlang_ls icon indicating copy to clipboard operation
erlang_ls copied to clipboard

Improve variable completion

Open misaki214 opened this issue 3 years ago • 5 comments

Is your feature request related to a problem? Please describe.

  • The code completion displays the variables of all functions before1

  • When the function is imcomplete, the variables in the function are not displayed. before2

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 after1 after2

misaki214 avatar Jun 09 '21 03:06 misaki214

Hi! I have two main questions about this approach:

  1. 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.
  2. 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.

robertoaloi avatar Jun 09 '21 06:06 robertoaloi

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 avatar Jun 09 '21 08:06 gomoripeti

@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.

robertoaloi avatar Jun 09 '21 09:06 robertoaloi

Regarding variable completion scope it seems like there are different preferences in the community. How about making that configurable?

plux avatar Jun 09 '21 17:06 plux

Regarding variable completion scope it seems like there are different preferences in the community. How about making that configurable?

I think so too.

misaki214 avatar Jun 10 '21 01:06 misaki214