@@ -187,4 +187,108 @@ defmodule ElixirLS.LanguageServer.Providers.CompletionTest do
187
187
assert % { "tags" => [ ] } = get_deprecated_completion_item ( tags_supported: [ 2 ] )
188
188
end
189
189
end
190
+
191
+ describe "structs and maps" do
192
+ test "returns struct fields in call syntax" do
193
+ text = """
194
+ defmodule MyModule do
195
+ defstruct [some: nil, other: 1]
196
+
197
+ def dummy_function(var = %MyModule{}) do
198
+ var.
199
+ # ^
200
+ end
201
+ end
202
+ """
203
+
204
+ { line , char } = { 4 , 8 }
205
+ TestUtils . assert_has_cursor_char ( text , line , char )
206
+ { :ok , % { "items" => items } } = Completion . completion ( text , line , char , @ supports )
207
+
208
+ assert [ "__struct__" , "other" , "some" ] == items |> Enum . map ( & & 1 [ "label" ] ) |> Enum . sort ( )
209
+ assert ( items |> hd ) [ "detail" ] == "MyModule struct field"
210
+ end
211
+
212
+ test "returns map keys in call syntax" do
213
+ text = """
214
+ defmodule MyModule do
215
+ def dummy_function(var = %{some: nil, other: 1}) do
216
+ var.
217
+ # ^
218
+ end
219
+ end
220
+ """
221
+
222
+ { line , char } = { 2 , 8 }
223
+ TestUtils . assert_has_cursor_char ( text , line , char )
224
+ { :ok , % { "items" => items } } = Completion . completion ( text , line , char , @ supports )
225
+
226
+ assert [ "other" , "some" ] == items |> Enum . map ( & & 1 [ "label" ] ) |> Enum . sort ( )
227
+ assert ( items |> hd ) [ "detail" ] == "map key"
228
+ end
229
+
230
+ test "returns struct fields in update syntax" do
231
+ text = """
232
+ defmodule MyModule do
233
+ defstruct [some: nil, other: 1]
234
+
235
+ def dummy_function(var = %MyModule{}) do
236
+ %{var |
237
+ # ^
238
+ end
239
+ end
240
+ """
241
+
242
+ { line , char } = { 4 , 11 }
243
+ TestUtils . assert_has_cursor_char ( text , line , char )
244
+ { :ok , % { "items" => items } } = Completion . completion ( text , line , char , @ supports )
245
+
246
+ assert [ "__struct__" , "other" , "some" ] ==
247
+ items |> Enum . filter ( & ( & 1 [ "kind" ] == 5 ) ) |> Enum . map ( & & 1 [ "label" ] ) |> Enum . sort ( )
248
+
249
+ assert ( items |> hd ) [ "detail" ] == "MyModule struct field"
250
+ end
251
+
252
+ test "returns map keys in update syntax" do
253
+ text = """
254
+ defmodule MyModule do
255
+ def dummy_function(var = %{some: nil, other: 1}) do
256
+ %{var |
257
+ # ^
258
+ end
259
+ end
260
+ """
261
+
262
+ { line , char } = { 2 , 11 }
263
+ TestUtils . assert_has_cursor_char ( text , line , char )
264
+ { :ok , % { "items" => items } } = Completion . completion ( text , line , char , @ supports )
265
+
266
+ assert [ "other" , "some" ] ==
267
+ items |> Enum . filter ( & ( & 1 [ "kind" ] == 5 ) ) |> Enum . map ( & & 1 [ "label" ] ) |> Enum . sort ( )
268
+
269
+ assert ( items |> hd ) [ "detail" ] == "map key"
270
+ end
271
+
272
+ test "returns struct fields in definition syntax" do
273
+ text = """
274
+ defmodule MyModule do
275
+ defstruct [some: nil, other: 1]
276
+
277
+ def dummy_function() do
278
+ %MyModule{}
279
+ # ^
280
+ end
281
+ end
282
+ """
283
+
284
+ { line , char } = { 4 , 14 }
285
+ TestUtils . assert_has_cursor_char ( text , line , char )
286
+ { :ok , % { "items" => items } } = Completion . completion ( text , line , char , @ supports )
287
+
288
+ assert [ "__struct__" , "other" , "some" ] ==
289
+ items |> Enum . filter ( & ( & 1 [ "kind" ] == 5 ) ) |> Enum . map ( & & 1 [ "label" ] ) |> Enum . sort ( )
290
+
291
+ assert ( items |> hd ) [ "detail" ] == "MyModule struct field"
292
+ end
293
+ end
190
294
end
0 commit comments