Skip to content

Commit 07f7300

Browse files
committed
Add test for completion of comprehensions
1 parent 56afc92 commit 07f7300

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-module(completion_more).
2+
3+
lc() ->
4+
[
5+
[].
6+
7+
mc() ->
8+
#{
9+
#{}.

apps/els_lsp/test/els_completion_SUITE.erl

+67-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
resolve_type_application_remote_external/1,
5252
resolve_opaque_application_remote_external/1,
5353
resolve_type_application_remote_otp/1,
54-
completion_request_fails/1
54+
completion_request_fails/1,
55+
list_comprehension/1,
56+
map_comprehension/1
5557
]).
5658

5759
%%==============================================================================
@@ -2052,3 +2054,67 @@ has_eep48(Module) ->
20522054

20532055
keywords() ->
20542056
els_completion_provider:keywords(test, test).
2057+
2058+
list_comprehension(Config) ->
2059+
Uri = ?config(completion_more_uri, Config),
2060+
TriggerKind = ?COMPLETION_TRIGGER_KIND_INVOKED,
2061+
%% Complete at [|
2062+
#{result := Result1} = els_client:completion(Uri, 4, 6, TriggerKind, <<>>),
2063+
?assertEqual(
2064+
[
2065+
#{
2066+
label => <<"[Expr || Elem <- List]">>,
2067+
kind => ?COMPLETION_ITEM_KIND_KEYWORD,
2068+
insertText => <<"${3:Expr} || ${2:Elem} <- ${1:List}]">>,
2069+
insertTextFormat => ?INSERT_TEXT_FORMAT_SNIPPET
2070+
}
2071+
],
2072+
Result1
2073+
),
2074+
%% Complete at [|]
2075+
#{result := Result2} =
2076+
els_client:completion(Uri, 5, 6, TriggerKind, <<>>),
2077+
?assertEqual(
2078+
[
2079+
#{
2080+
label => <<"[Expr || Elem <- List]">>,
2081+
kind => ?COMPLETION_ITEM_KIND_KEYWORD,
2082+
insertText => <<"${3:Expr} || ${2:Elem} <- ${1:List}">>,
2083+
insertTextFormat => ?INSERT_TEXT_FORMAT_SNIPPET
2084+
}
2085+
],
2086+
Result2
2087+
).
2088+
2089+
map_comprehension(Config) ->
2090+
Uri = ?config(completion_more_uri, Config),
2091+
TriggerKind = ?COMPLETION_TRIGGER_KIND_INVOKED,
2092+
%% Complete at #{|
2093+
#{result := Result1} = els_client:completion(Uri, 8, 7, TriggerKind, <<>>),
2094+
?assertEqual(
2095+
[
2096+
#{
2097+
label => <<"#{K => V || K := V <- Map}">>,
2098+
kind => ?COMPLETION_ITEM_KIND_KEYWORD,
2099+
insertText =>
2100+
<<"${4:K} => ${5:V} || ${2:K} => ${3:V} <- ${1:Map}}">>,
2101+
insertTextFormat => ?INSERT_TEXT_FORMAT_SNIPPET
2102+
}
2103+
],
2104+
Result1
2105+
),
2106+
%% Complete at #{|}
2107+
#{result := Result2} =
2108+
els_client:completion(Uri, 9, 7, TriggerKind, <<>>),
2109+
?assertEqual(
2110+
[
2111+
#{
2112+
label => <<"#{K => V || K := V <- Map}">>,
2113+
kind => ?COMPLETION_ITEM_KIND_KEYWORD,
2114+
insertText =>
2115+
<<"${4:K} => ${5:V} || ${2:K} => ${3:V} <- ${1:Map}">>,
2116+
insertTextFormat => ?INSERT_TEXT_FORMAT_SNIPPET
2117+
}
2118+
],
2119+
Result2
2120+
).

0 commit comments

Comments
 (0)