@@ -157,6 +157,7 @@ render(Module, Function, #docs_v1{docs = Docs} = D, Config) when
157
157
Docs
158
158
),
159
159
D ,
160
+ Module ,
160
161
Config
161
162
);
162
163
render (_Module , Function , Arity , # docs_v1 {} = D ) ->
@@ -183,6 +184,7 @@ render(Module, Function, Arity, #docs_v1{docs = Docs} = D, Config) when
183
184
Docs
184
185
),
185
186
D ,
187
+ Module ,
186
188
Config
187
189
).
188
190
@@ -210,7 +212,7 @@ render_type(Module, Type, D = #docs_v1{}) ->
210
212
Arity :: arity (),
211
213
Docs :: docs_v1 (),
212
214
Res :: unicode :chardata () | {error , type_missing }.
213
- render_type (_Module , Type , # docs_v1 {docs = Docs } = D , Config ) ->
215
+ render_type (Module , Type , # docs_v1 {docs = Docs } = D , Config ) ->
214
216
render_typecb_docs (
215
217
lists :filter (
216
218
fun
@@ -222,6 +224,7 @@ render_type(_Module, Type, #docs_v1{docs = Docs} = D, Config) ->
222
224
Docs
223
225
),
224
226
D ,
227
+ Module ,
225
228
Config
226
229
);
227
230
render_type (_Module , Type , Arity , # docs_v1 {} = D ) ->
@@ -234,7 +237,7 @@ render_type(_Module, Type, Arity, #docs_v1{} = D) ->
234
237
Docs :: docs_v1 (),
235
238
Config :: config (),
236
239
Res :: unicode :chardata () | {error , type_missing }.
237
- render_type (_Module , Type , Arity , # docs_v1 {docs = Docs } = D , Config ) ->
240
+ render_type (Module , Type , Arity , # docs_v1 {docs = Docs } = D , Config ) ->
238
241
render_typecb_docs (
239
242
lists :filter (
240
243
fun
@@ -246,6 +249,7 @@ render_type(_Module, Type, Arity, #docs_v1{docs = Docs} = D, Config) ->
246
249
Docs
247
250
),
248
251
D ,
252
+ Module ,
249
253
Config
250
254
).
251
255
@@ -275,7 +279,7 @@ render_callback(_Module, Callback, #docs_v1{} = D) ->
275
279
Res :: unicode :chardata () | {error , callback_missing }.
276
280
render_callback (_Module , Callback , Arity , # docs_v1 {} = D ) ->
277
281
render_callback (_Module , Callback , Arity , D , #{});
278
- render_callback (_Module , Callback , # docs_v1 {docs = Docs } = D , Config ) ->
282
+ render_callback (Module , Callback , # docs_v1 {docs = Docs } = D , Config ) ->
279
283
render_typecb_docs (
280
284
lists :filter (
281
285
fun
@@ -287,6 +291,7 @@ render_callback(_Module, Callback, #docs_v1{docs = Docs} = D, Config) ->
287
291
Docs
288
292
),
289
293
D ,
294
+ Module ,
290
295
Config
291
296
).
292
297
@@ -297,7 +302,7 @@ render_callback(_Module, Callback, #docs_v1{docs = Docs} = D, Config) ->
297
302
Docs :: docs_v1 (),
298
303
Config :: config (),
299
304
Res :: unicode :chardata () | {error , callback_missing }.
300
- render_callback (_Module , Callback , Arity , # docs_v1 {docs = Docs } = D , Config ) ->
305
+ render_callback (Module , Callback , Arity , # docs_v1 {docs = Docs } = D , Config ) ->
301
306
render_typecb_docs (
302
307
lists :filter (
303
308
fun
@@ -309,6 +314,7 @@ render_callback(_Module, Callback, Arity, #docs_v1{docs = Docs} = D, Config) ->
309
314
Docs
310
315
),
311
316
D ,
317
+ Module ,
312
318
Config
313
319
).
314
320
@@ -353,11 +359,11 @@ normalize_format(Docs, #docs_v1{format = <<"text/", _/binary>>}) when is_binary(
353
359
[{pre , [], [Docs ]}].
354
360
355
361
% %% Functions for rendering reference documentation
356
- - spec render_function ([chunk_entry ()], # docs_v1 {}, map ()) ->
362
+ - spec render_function ([chunk_entry ()], # docs_v1 {}, atom (), map ()) ->
357
363
unicode :chardata () | {'error' , 'function_missing' }.
358
- render_function ([], _D , _Config ) ->
364
+ render_function ([], _D , _Module , _Config ) ->
359
365
{error , function_missing };
360
- render_function (FDocs , # docs_v1 {docs = Docs } = D , Config ) ->
366
+ render_function (FDocs , # docs_v1 {docs = Docs } = D , Module , Config ) ->
361
367
Grouping =
362
368
lists :foldl (
363
369
fun
@@ -375,7 +381,7 @@ render_function(FDocs, #docs_v1{docs = Docs} = D, Config) ->
375
381
fun ({Group , Members }) ->
376
382
lists :map (
377
383
fun (Member = {_ , _ , _ , Doc , _ }) ->
378
- Sig = render_signature (Member ),
384
+ Sig = render_signature (Member , Module ),
379
385
LocalDoc =
380
386
if
381
387
Doc =:= #{} ->
@@ -399,8 +405,8 @@ render_function(FDocs, #docs_v1{docs = Docs} = D, Config) ->
399
405
).
400
406
401
407
% % Render the signature of either function, type, or anything else really.
402
- - spec render_signature (chunk_entry ()) -> chunk_elements ().
403
- render_signature ({{_Type , _F , _A }, _Anno , _Sigs , _Docs , #{signature := Specs } = Meta }) ->
408
+ - spec render_signature (chunk_entry (), module ()) -> chunk_elements () | els_poi : poi ().
409
+ render_signature ({{_Type , _F , _A }, _Anno , _Sigs , _Docs , #{signature := Specs } = Meta }, _Module ) ->
404
410
lists :flatmap (
405
411
fun (ASTSpec ) ->
406
412
PPSpec = erl_pp :attribute (ASTSpec , [{encoding , utf8 }]),
@@ -424,8 +430,13 @@ render_signature({{_Type, _F, _A}, _Anno, _Sigs, _Docs, #{signature := Specs} =
424
430
end ,
425
431
Specs
426
432
);
427
- render_signature ({{_Type , _F , _A }, _Anno , Sigs , _Docs , Meta }) ->
428
- [{pre , [], Sigs }, {hr , [], []} | render_meta (Meta )].
433
+ render_signature ({{_Type , F , A }, _Anno , Sigs , _Docs , Meta }, Module ) ->
434
+ case els_dt_signatures :lookup ({Module , F , A }) of
435
+ {ok , [#{spec := <<" -spec " , Spec /binary >>}]} ->
436
+ [{pre , [], Spec }, {hr , [], []} | render_meta (Meta )];
437
+ {ok , _ } ->
438
+ [{pre , [], Sigs }, {hr , [], []} | render_meta (Meta )]
439
+ end .
429
440
430
441
- spec trim_spec (unicode :chardata ()) -> unicode :chardata ().
431
442
trim_spec (Spec ) ->
@@ -499,7 +510,7 @@ render_headers_and_docs(Headers, DocContents, #config{} = Config) ->
499
510
render_docs (DocContents , 0 , Config )
500
511
].
501
512
502
- - spec render_typecb_docs ([TypeCB ] | TypeCB , # config {}) ->
513
+ - spec render_typecb_docs ([TypeCB ] | TypeCB , module (), # config {}) ->
503
514
unicode :chardata () | {'error' , 'type_missing' }
504
515
when
505
516
TypeCB :: {
@@ -508,16 +519,20 @@ when
508
519
Sig :: [binary ()],
509
520
none | hidden | #{binary () => chunk_elements ()}
510
521
}.
511
- render_typecb_docs ([], _C ) ->
522
+ render_typecb_docs ([], _Module , _C ) ->
512
523
{error , type_missing };
513
- render_typecb_docs (TypeCBs , # config {} = C ) when is_list (TypeCBs ) ->
514
- [render_typecb_docs (TypeCB , C ) || TypeCB <- TypeCBs ];
515
- render_typecb_docs ({F , _ , _Sig , Docs , _Meta } = TypeCB , # config {docs = D } = C ) ->
516
- render_headers_and_docs (render_signature (TypeCB ), get_local_doc (F , Docs , D ), C ).
517
- - spec render_typecb_docs (chunk_elements (), # docs_v1 {}, _ ) ->
524
+ render_typecb_docs (TypeCBs , Module , # config {} = C ) when is_list (TypeCBs ) ->
525
+ [render_typecb_docs (TypeCB , Module , C ) || TypeCB <- TypeCBs ];
526
+ render_typecb_docs ({F , _ , _Sig , Docs , _Meta } = TypeCB , Module , # config {docs = D } = C ) ->
527
+ render_headers_and_docs (
528
+ render_signature (TypeCB , Module ),
529
+ get_local_doc (F , Docs , D ),
530
+ C
531
+ ).
532
+ - spec render_typecb_docs (chunk_elements (), # docs_v1 {}, module (), _ ) ->
518
533
unicode :chardata () | {'error' , 'type_missing' }.
519
- render_typecb_docs (Docs , D , Config ) ->
520
- render_typecb_docs (Docs , init_config (D , Config )).
534
+ render_typecb_docs (Docs , D , Module , Config ) ->
535
+ render_typecb_docs (Docs , Module , init_config (D , Config )).
521
536
522
537
% %% General rendering functions
523
538
- spec render_docs ([chunk_element ()], # config {}) -> unicode :chardata ().
@@ -540,6 +555,12 @@ init_config(D, _Config) ->
540
555
# config {}
541
556
) ->
542
557
{unicode :chardata (), non_neg_integer ()}.
558
+ render_docs (Str , State , Pos , Ind , D ) when
559
+ is_list (Str ),
560
+ is_integer (hd (Str ))
561
+ ->
562
+ % % This is a string, convert it to binary.
563
+ render_docs ([unicode :characters_to_binary (Str )], State , Pos , Ind , D );
543
564
render_docs (Elems , State , Pos , Ind , D ) when is_list (Elems ) ->
544
565
lists :mapfoldl (
545
566
fun (Elem , P ) ->
0 commit comments