@@ -56,6 +56,7 @@ defmodule ElixirLS.Utils.CompletionEngine do
56
56
alias ElixirSense.Core.Normalized.Code , as: NormalizedCode
57
57
alias ElixirSense.Core.Source
58
58
alias ElixirSense.Core.State
59
+ alias ElixirSense.Core.State.StructInfo
59
60
alias ElixirSense.Core.Struct
60
61
alias ElixirSense.Core.TypeInfo
61
62
@@ -111,7 +112,9 @@ defmodule ElixirLS.Utils.CompletionEngine do
111
112
name: String . t ( ) ,
112
113
origin: String . t ( ) | nil ,
113
114
call?: boolean ,
114
- type_spec: String . t ( ) | nil
115
+ type_spec: String . t ( ) | nil ,
116
+ summary: String . t ( ) ,
117
+ metadata: map
115
118
}
116
119
117
120
@ type t ( ) ::
@@ -1370,8 +1373,35 @@ defmodule ElixirLS.Utils.CompletionEngine do
1370
1373
defp ensure_loaded ( Elixir ) , do: { :error , :nofile }
1371
1374
defp ensure_loaded ( mod ) , do: Code . ensure_compiled ( mod )
1372
1375
1376
+ defp get_struct_info ( { :atom , module } , metadata ) when is_atom ( module ) do
1377
+ case metadata . structs [ module ] do
1378
+ % StructInfo { } = info ->
1379
+ { info . doc , info . meta }
1380
+
1381
+ nil ->
1382
+ case NormalizedCode . get_docs ( module , :docs ) do
1383
+ nil ->
1384
+ { "" , % { } }
1385
+
1386
+ docs ->
1387
+ case Enum . find ( docs , fn
1388
+ { { :__struct__ , 0 } , _ , _ , _ , _ , _ } -> true
1389
+ _ -> false
1390
+ end ) do
1391
+ { { :__struct__ , 0 } , _ , _ , _ , doc , meta } ->
1392
+ { doc || "" , meta }
1393
+
1394
+ _ ->
1395
+ { "" , % { } }
1396
+ end
1397
+ end
1398
+ end
1399
+ end
1400
+
1401
+ defp get_struct_info ( _ , _metadata ) , do: { "" , % { } }
1402
+
1373
1403
defp match_map_fields ( fields , hint , type , % State.Env { } = _env , % Metadata { } = metadata ) do
1374
- { subtype , origin , types } =
1404
+ { subtype , origin , types , doc , meta } =
1375
1405
case type do
1376
1406
{ :struct , { :atom , mod } } ->
1377
1407
types =
@@ -1381,13 +1411,14 @@ defmodule ElixirLS.Utils.CompletionEngine do
1381
1411
true
1382
1412
)
1383
1413
1384
- { :struct_field , inspect ( mod ) , types }
1414
+ { doc , meta } = get_struct_info ( { :atom , mod } , metadata )
1415
+ { :struct_field , inspect ( mod ) , types , doc , meta }
1385
1416
1386
1417
{ :struct , nil } ->
1387
- { :struct_field , nil , % { } }
1418
+ { :struct_field , nil , % { } , "" , % { } }
1388
1419
1389
1420
:map ->
1390
- { :map_key , nil , % { } }
1421
+ { :map_key , nil , % { } , "" , % { } }
1391
1422
1392
1423
other ->
1393
1424
raise "unexpected #{ inspect ( other ) } for hint #{ inspect ( hint ) } "
@@ -1410,7 +1441,9 @@ defmodule ElixirLS.Utils.CompletionEngine do
1410
1441
subtype: subtype ,
1411
1442
value_is_map: value_is_map ,
1412
1443
origin: origin ,
1413
- type_spec: types [ key ]
1444
+ type_spec: types [ key ] ,
1445
+ summary: doc ,
1446
+ metadata: meta
1414
1447
}
1415
1448
end
1416
1449
|> Enum . sort_by ( & & 1 . name )
@@ -1423,7 +1456,9 @@ defmodule ElixirLS.Utils.CompletionEngine do
1423
1456
subtype: subtype ,
1424
1457
name: name ,
1425
1458
origin: origin ,
1426
- type_spec: type_spec
1459
+ type_spec: type_spec ,
1460
+ summary: summary ,
1461
+ metadata: metadata
1427
1462
} ) do
1428
1463
[
1429
1464
% {
@@ -1432,7 +1467,9 @@ defmodule ElixirLS.Utils.CompletionEngine do
1432
1467
subtype: subtype ,
1433
1468
origin: origin ,
1434
1469
call?: true ,
1435
- type_spec: if ( type_spec , do: Macro . to_string ( type_spec ) )
1470
+ type_spec: if ( type_spec , do: Macro . to_string ( type_spec ) ) ,
1471
+ summary: summary ,
1472
+ metadata: metadata
1436
1473
}
1437
1474
]
1438
1475
end
0 commit comments