Open
Description
Describe the bug
I would like to have better auto-complete support, such as what is available in the Erlang shell.
Expected behavior
Today you can call this in an Erlang system:
1> edlin_expand:expand(lists:reverse("gen_tcp:connect(localhost,80, ["),[]).
{no,[],
[#{options => [highlight_all],
title => "typespecs",
elems =>
[#{options => [{highlight_param,3}],
title => "gen_tcp:connect(Address, Port, Opts)",
elems =>
[#{options => [{hide,title}],
title => "types",
elems =>
[#{options => [{separator," :: "},{highlight_all}],
title => "inet:inet_backend()",
elems => [{"{inet_backend, ...}",[]}]},
#{options => [{separator," :: "},{highlight_all}],
title => "gen_tcp:connect_option()",
elems =>
[{"{fd, ...}",[]},
{"inet",[]},
{"inet6",[]},
{"local",[]},
{"{ifaddr, ...}",[]},
{"{ip, ...}",[]},
{"{port, ...}",[]},
{"{tcp_module, ...}",[]},
{"{netns, ...}",[]},
{"{bind_to_device, ...}",[]},
{"{active, ...}",[]},
{"{buffer, ...}",[]},
{"{debug, ...}",[]},
{"{delay_send, ...}",[]},
{"{deliver, ...}",[]},
{"{dontroute, ...}",[]},
....
You get a list of all the different options that gen_tcp accepts, and then if you do:
2> edlin_expand:expand(lists:reverse("gen_tcp:connect(localhost,80, [{active,"),[]).
{no,[],
[#{options => [highlight_all],
title => "typespecs",
elems =>
[#{options => [{highlight_param,3}],
title => "gen_tcp:connect(Address, Port, Opts)",
elems =>
[#{options => [{hide,title}],
title => "types",
elems =>
[{"true",[]},
{"false",[]},
{"once",[]},
{"range(op (- 32768), 32767)",[]}]}]},
#{options => [{highlight_param,3}],
title => "gen_tcp:connect(Address, Port, Opts, Timeout)",
elems =>
[#{options => [{hide,title}],
title => "types",
elems =>
[{"true",[]},
{"false",[]},
{"once",[]},
{"range(op (- 32768), 32767)",[]}]}]}]}]}
you get only the things allowed as {active,
option. The data by this is triven by the function specs found in the system. The return format is documented here: https://www.erlang.org/doc/apps/stdlib/edlin_expand.html
I would like ELP to either use the output from edlin_expand directly to provide autocomplete results, or that we create a new API in Erlang/OTP that ELP can use. Elixir has something call Code.Fragment
which works similarly to what I have in mind.
What do you think?
/cc @frazze-jobb