@@ -95,10 +95,6 @@ defmodule ElixirLS.LanguageServer.MarkdownUtils do
95
95
"**Since** #{ text } "
96
96
end
97
97
98
- defp get_metadata_entry_md ( { :group , text } ) when is_binary ( text ) do
99
- "**Group** #{ text } "
100
- end
101
-
102
98
defp get_metadata_entry_md ( { :guard , true } ) do
103
99
"**Guard**"
104
100
end
@@ -249,13 +245,21 @@ defmodule ElixirLS.LanguageServer.MarkdownUtils do
249
245
{ key , url }
250
246
end )
251
247
248
+ @ erlang_ex_doc? System . otp_release ( ) |> String . to_integer ( ) >= 27
249
+
252
250
def transform_ex_doc_link ( "t:" <> rest , current_module ) do
253
251
case @ builtin_type_url [ rest ] do
254
252
nil ->
255
253
case get_module_fun_arity ( rest ) do
256
254
{ module , type , arity } ->
257
255
if match? ( ":" <> _ , rest ) do
258
- "https://www.erlang.org/doc/man/#{ module } .html#type-#{ type } "
256
+ if @ erlang_ex_doc? do
257
+ # TODO not sure hos the docs will handle versions app/vsn does not work as of June 2024
258
+ { app , _vsn } = DocLinks . get_app ( module )
259
+ "https://www.erlang.org/doc/apps/#{ app } /#{ module } .html#t:#{ type } /#{ arity } "
260
+ else
261
+ "https://www.erlang.org/doc/man/#{ module } .html#type-#{ type } "
262
+ end
259
263
else
260
264
DocLinks . hex_docs_type_link ( module || current_module , type , arity )
261
265
end
@@ -270,7 +274,13 @@ defmodule ElixirLS.LanguageServer.MarkdownUtils do
270
274
case get_module_fun_arity ( rest ) do
271
275
{ module , callback , arity } ->
272
276
if match? ( ":" <> _ , rest ) do
273
- "https://www.erlang.org/doc/man/#{ module } .html#Module:#{ callback } -#{ arity } "
277
+ if @ erlang_ex_doc? do
278
+ # TODO not sure hos the docs will handle versions app/vsn does not work as of June 2024
279
+ { app , _vsn } = DocLinks . get_app ( module )
280
+ "https://www.erlang.org/doc/apps/#{ app } /#{ module } .html#c:#{ callback } /#{ arity } "
281
+ else
282
+ "https://www.erlang.org/doc/man/#{ module } .html#Module:#{ callback } -#{ arity } "
283
+ end
274
284
else
275
285
DocLinks . hex_docs_callback_link ( module || current_module , callback , arity )
276
286
end
@@ -280,6 +290,32 @@ defmodule ElixirLS.LanguageServer.MarkdownUtils do
280
290
def transform_ex_doc_link ( "e:http://" <> rest , _current_module ) , do: "http://" <> rest
281
291
def transform_ex_doc_link ( "e:https://" <> rest , _current_module ) , do: "https://" <> rest
282
292
293
+ otp_apps_dir =
294
+ :code . get_object_code ( :erlang ) |> elem ( 2 ) |> Path . join ( "../../.." ) |> Path . expand ( )
295
+
296
+ @ all_otp_apps otp_apps_dir
297
+ |> File . ls! ( )
298
+ |> Enum . map ( & ( & 1 |> String . split ( "-" ) |> hd ( ) |> String . to_atom ( ) ) )
299
+
300
+ if @ erlang_ex_doc? do
301
+ def transform_ex_doc_link ( "e:system:" <> rest , _current_module ) do
302
+ { page , anchor } = split ( rest )
303
+
304
+ page =
305
+ page
306
+ |> String . replace ( ~r/ \. (md|livemd|cheatmd|txt)$/ , ".html" )
307
+ |> String . replace ( " " , "-" )
308
+ |> String . downcase ( )
309
+
310
+ "https://www.erlang.org/doc/system/#{ page } " <>
311
+ if anchor do
312
+ "#" <> anchor
313
+ else
314
+ ""
315
+ end
316
+ end
317
+ end
318
+
283
319
def transform_ex_doc_link ( "e:" <> rest , current_module ) do
284
320
{ page , anchor } = split ( rest )
285
321
@@ -291,7 +327,7 @@ defmodule ElixirLS.LanguageServer.MarkdownUtils do
291
327
292
328
page =
293
329
page
294
- |> String . replace ( ~r/ \. (md|livemd|txt)$/ , ".html" )
330
+ |> String . replace ( ~r/ \. (md|livemd|cheatmd| txt)$/ , ".html" )
295
331
|> String . replace ( " " , "-" )
296
332
|> String . downcase ( )
297
333
@@ -321,7 +357,14 @@ defmodule ElixirLS.LanguageServer.MarkdownUtils do
321
357
end
322
358
323
359
if app_vsn do
324
- DocLinks . hex_docs_extra_link ( app_vsn , page ) <>
360
+ { app , _vsn } = app_vsn
361
+
362
+ if app in @ all_otp_apps and @ erlang_ex_doc? do
363
+ # TODO not sure hos the docs will handle versions app/vsn does not work as of June 2024
364
+ "https://www.erlang.org/doc/apps/#{ app } /#{ page } "
365
+ else
366
+ DocLinks . hex_docs_extra_link ( app_vsn , page )
367
+ end <>
325
368
if anchor do
326
369
"#" <> anchor
327
370
else
@@ -344,7 +387,13 @@ defmodule ElixirLS.LanguageServer.MarkdownUtils do
344
387
345
388
{ module , function , arity } ->
346
389
if match? ( ":" <> _ , prefix ) and module != Kernel.SpecialForms do
347
- "https://www.erlang.org/doc/man/#{ module } .html##{ function } -#{ arity } "
390
+ if @ erlang_ex_doc? do
391
+ # TODO not sure hos the docs will handle versions app/vsn does not work as of June 2024
392
+ { app , _vsn } = DocLinks . get_app ( module )
393
+ "https://www.erlang.org/doc/apps/#{ app } /#{ module } .html##{ function } /#{ arity } "
394
+ else
395
+ "https://www.erlang.org/doc/man/#{ module } .html##{ function } -#{ arity } "
396
+ end
348
397
else
349
398
DocLinks . hex_docs_function_link ( module || current_module , function , arity )
350
399
end
0 commit comments