erlang_ls icon indicating copy to clipboard operation
erlang_ls copied to clipboard

add completion for clauses

Open TheGeorge opened this issue 3 years ago • 9 comments

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

Screenshot 2022-04-04 at 15 54 19

results into

Screenshot 2022-04-04 at 15 54 26

TheGeorge avatar Apr 04 '22 14:04 TheGeorge

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

michalmuskala avatar Apr 04 '22 17:04 michalmuskala

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:

Screenshot 2022-04-06 at 09 14 02

Screenshot 2022-04-06 at 09 14 08

TheGeorge avatar Apr 06 '22 08:04 TheGeorge

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?

michalmuskala avatar Apr 06 '22 08:04 michalmuskala

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.

TheGeorge avatar Apr 06 '22 08:04 TheGeorge

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 avatar Apr 20 '22 18:04 TheGeorge

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

robertoaloi avatar Apr 27 '22 10:04 robertoaloi

Added tests and Ci should now work after windows CI fix.

TheGeorge avatar May 03 '22 12:05 TheGeorge

@TheGeorge Should we try and get this one in? There are some unresolved conflicts.

robertoaloi avatar Jun 13 '22 07:06 robertoaloi

Yeah, just need to rebase after formatting

TheGeorge avatar Aug 01 '22 18:08 TheGeorge

dropped for now

TheGeorge avatar Sep 16 '22 09:09 TheGeorge