@@ -56,6 +56,7 @@ defmodule ElixirLS.Utils.CompletionEngine do
5656 alias ElixirSense.Core.Normalized.Code , as: NormalizedCode
5757 alias ElixirSense.Core.Source
5858 alias ElixirSense.Core.State
59+ alias ElixirSense.Core.State.StructInfo
5960 alias ElixirSense.Core.Struct
6061 alias ElixirSense.Core.TypeInfo
6162
@@ -111,7 +112,9 @@ defmodule ElixirLS.Utils.CompletionEngine do
111112 name: String . t ( ) ,
112113 origin: String . t ( ) | nil ,
113114 call?: boolean ,
114- type_spec: String . t ( ) | nil
115+ type_spec: String . t ( ) | nil ,
116+ summary: String . t ( ) ,
117+ metadata: map
115118 }
116119
117120 @ type t ( ) ::
@@ -1370,8 +1373,35 @@ defmodule ElixirLS.Utils.CompletionEngine do
13701373 defp ensure_loaded ( Elixir ) , do: { :error , :nofile }
13711374 defp ensure_loaded ( mod ) , do: Code . ensure_compiled ( mod )
13721375
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+
13731403 defp match_map_fields ( fields , hint , type , % State.Env { } = _env , % Metadata { } = metadata ) do
1374- { subtype , origin , types } =
1404+ { subtype , origin , types , doc , meta } =
13751405 case type do
13761406 { :struct , { :atom , mod } } ->
13771407 types =
@@ -1381,13 +1411,14 @@ defmodule ElixirLS.Utils.CompletionEngine do
13811411 true
13821412 )
13831413
1384- { :struct_field , inspect ( mod ) , types }
1414+ { doc , meta } = get_struct_info ( { :atom , mod } , metadata )
1415+ { :struct_field , inspect ( mod ) , types , doc , meta }
13851416
13861417 { :struct , nil } ->
1387- { :struct_field , nil , % { } }
1418+ { :struct_field , nil , % { } , "" , % { } }
13881419
13891420 :map ->
1390- { :map_key , nil , % { } }
1421+ { :map_key , nil , % { } , "" , % { } }
13911422
13921423 other ->
13931424 raise "unexpected #{ inspect ( other ) } for hint #{ inspect ( hint ) } "
@@ -1410,7 +1441,9 @@ defmodule ElixirLS.Utils.CompletionEngine do
14101441 subtype: subtype ,
14111442 value_is_map: value_is_map ,
14121443 origin: origin ,
1413- type_spec: types [ key ]
1444+ type_spec: types [ key ] ,
1445+ summary: doc ,
1446+ metadata: meta
14141447 }
14151448 end
14161449 |> Enum . sort_by ( & & 1 . name )
@@ -1423,7 +1456,9 @@ defmodule ElixirLS.Utils.CompletionEngine do
14231456 subtype: subtype ,
14241457 name: name ,
14251458 origin: origin ,
1426- type_spec: type_spec
1459+ type_spec: type_spec ,
1460+ summary: summary ,
1461+ metadata: metadata
14271462 } ) do
14281463 [
14291464 % {
@@ -1432,7 +1467,9 @@ defmodule ElixirLS.Utils.CompletionEngine do
14321467 subtype: subtype ,
14331468 origin: origin ,
14341469 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
14361473 }
14371474 ]
14381475 end
0 commit comments