Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions lib/ex_doc/formatter/html/autolink.ex
Original file line number Diff line number Diff line change
Expand Up @@ -542,27 +542,38 @@ defmodule ExDoc.Formatter.HTML.Autolink do
case Application.fetch_env(:ex_doc, :elixir_lib_dirs) do
{:ok, lib_dirs} ->
lib_dirs
:error ->
lib_dir =
case :code.where_is_file('Elixir.Kernel.beam') do
:non_existing ->
[0]
path ->
path
|> Path.dirname()
|> Path.dirname()
|> Path.dirname()
end

:error ->
lib_dirs =
for app <- ~w(elixir eex iex logger mix ex_unit) do
{lib_dir <> "/" <> app <> "/ebin", @elixir_docs <> app <> "/"}
{elixir_lib_dir(app), @elixir_docs <> app <> "/"}
end

Application.put_env(:ex_doc, :elixir_lib_dirs, lib_dirs)
lib_dirs
end
end

defp elixir_lib_dir(app) do
path =
case :code.where_is_file('Elixir.Kernel.beam') do
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately we won't be able to autolink things from Mix, IEx etc because they're not loaded.

:non_existing -> ""
path -> List.to_string(path)
end

if File.exists?(path) do
path =
path
|> Path.dirname()
|> Path.dirname()
|> Path.dirname()
path <> "/" <> app <> "/ebin"
else
# if beam file doesn't exists it's likely an escript
Path.dirname(path)
end
end

defp erlang_lib_dirs do
case Application.fetch_env(:ex_doc, :erlang_lib_dirs) do
{:ok, lib_dirs} ->
Expand Down
1 change: 1 addition & 0 deletions test/ex_doc/formatter/html/autolink_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ defmodule ExDoc.Formatter.HTML.AutolinkTest do
# links to types without arity don't work
assert Autolink.local_doc("`t:my_type`", ["t:my_type/0"]) == "`t:my_type`"
end

test "autolink to basic and built-in types" do
assert Autolink.local_doc("`t:atom/0`", []) ==
"[`atom/0`](#{@elixir_docs}elixir/typespecs.html#basic-types)"
Expand Down