lexical-lsp / lexical

Lexical is a next-generation elixir language server
776 stars 77 forks source link

Improve capture completions in capture context #773

Open zachallaun opened 2 weeks ago

zachallaun commented 2 weeks ago

Completions in a capture context can be improved in a number of ways. In the following examples, consider that you have a function/1 and function/2 in scope.


Improve labels

If we're in a capture context, it would be nice if completions started with & to indicate that it is being considered in the completion responses.

&fun|

# desired completions:
# &function(arg1)
# &function/1
# &function(arg1, arg2)
# &function/2

Using additional &fun/arity context

When /arity is present, it should be used to improve completions.

&fun|/2

# current completions:
# function(arg1)
# function/1
# function(arg1, arg2)
# function/2

# desired completions:
# &function/2
# &function(arg1, arg2)
# &function/1
# &function(arg1)

Additionally:


Using additional &fun(arg) context

When (arg, ...) is present, it should be used to improve completions.

&fun|/(&1,  arg)

# current completions:
# function(arg1)
# function/1
# function(arg1, arg2)
# function/2

# desired completions:
# &function(arg1, arg2)
# &function/2
# &function(arg1)
# &function/1

Additionally:

zachallaun commented 2 weeks ago

Regarding sorting: Currently function/2 and function(arg1, arg2) return the same sort text.

zachallaun commented 2 weeks ago

Regarding prefixing labels with &: maybe this shouldn't be done, as it confuses things somewhat for qualified captures:

&Enum.reduce_w|

# completions:
# reduce_while/3
# reduce_while(enumerable, acc fun)

It might be confusing for the completions to include &, e.g. &reduce_while/3, since what we're really completing is &Enum.reduce_while/3.