erlang_ls
                                
                                 erlang_ls copied to clipboard
                                
                                    erlang_ls copied to clipboard
                            
                            
                            
                        add completion for clauses
Description
Adds completion support for clauses. The trigger is ; ~~and it currently only support top-level functions. What's missing is completion for:~~
- ~~funs~~
- ~~receives~~
- ~~try / catch~~
- ~~case~~
Example

results into

I think the behaviour I'd prefer is that on the newline when I start typing the name of the function, it offers to complete, so rather something like:
foo(A, B, C) -> ok;
f|
complete shows up, and fills:
foo(A, B, C) -> ok;
foo(A, B, C) -> |
This should work in more cases, including when you're adding a clause in the middle of a function, and not just when first writing out the clauses top-down
Interesting angle, having it trigger on the ; is inspired from how emacs completes clauses. I somewhat disagree with suggestion, because extending from the last ; (besides emacs) is a workflow that is quite common, e.g. markdown editors, other word processors, or even extending comments. So it's a pattern most people are used to already.
in the middle of a function
This still works, when triggering completion from the middle clause ;. It doesn't need to be the last clause:


My reasoning is that this is in general how completion works - you start typing the name, and it's completed for you. Doing this for clauses seems very natural to me.
Actually, it seems this already works today:
https://user-images.githubusercontent.com/477062/161929103-37780234-e462-4180-99aa-64f1a1bcd96e.mov
Re: adding it in the middle - does this trigger when you just "stand" on a ; vs when you just typed it in?
Re: adding it in the middle - does this trigger when you just "stand" on a ; vs when you just typed it in?
The LSP has 3 trigger types:
- character (typing ;)
- invoked (ctrl + SPACE)
- for incomplete completion (when completion list was not complete due to partial result returned)
The one in the middle I triggered with ctrl+SPACE
My reasoning is that this is in general how completion works - you start typing the name, and it's completed for you. Doing this for clauses seems very natural to me.
Granted, this is abusing the completion functionality somewhat, to add something similar to the on-enter rules in language-configuration.json, but with the ability to add a proper snippet with function args.
https://user-images.githubusercontent.com/292239/164294104-da5a8aea-86c5-45dc-8fbe-7d015bf42ade.mov
This now supports completion of arbitrary clauses and is context sensitive
@TheGeorge I tried the feature in both VS Code and Emacs. It looks good in VS Code and I don't get it for some reason in Emacs (which is good, since I prefer the Emacs version). So, no concerns from my side.
Added tests and Ci should now work after windows CI fix.
@TheGeorge Should we try and get this one in? There are some unresolved conflicts.
Yeah, just need to rebase after formatting
dropped for now