@@ -62,6 +62,7 @@ defmodule ExDoc.Autolink do
62
62
63
63
@ hexdocs "https://hexdocs.pm/"
64
64
@ otpdocs "https://www.erlang.org/doc/man/"
65
+ @ otpappdocs "https://www.erlang.org/doc/apps/"
65
66
66
67
def app_module_url ( tool , module , anchor \\ nil , config )
67
68
@@ -121,50 +122,45 @@ defmodule ExDoc.Autolink do
121
122
end
122
123
123
124
defp app ( module ) do
124
- { _ , app } = app_info ( module )
125
- app
125
+ case :code . which ( module ) do
126
+ :preloaded ->
127
+ :erts
128
+
129
+ maybe_path ->
130
+ case :application . get_application ( module ) do
131
+ { :ok , app } ->
132
+ app
133
+
134
+ _ ->
135
+ with true <- is_list ( maybe_path ) ,
136
+ [ _ , "ebin" , app , "lib" | _ ] <- maybe_path |> Path . split ( ) |> Enum . reverse ( ) do
137
+ String . split ( app , "-" ) |> hd ( ) |> String . to_atom ( )
138
+ else
139
+ _ -> nil
140
+ end
141
+ end
142
+ end
126
143
end
127
144
128
145
@ doc false
129
146
def tool ( module , config ) do
130
147
if match? ( "Elixir." <> _ , Atom . to_string ( module ) ) do
131
148
:ex_doc
132
149
else
133
- { otp , app } = app_info ( module )
150
+ app = app ( module )
134
151
apps = Enum . uniq ( config . apps ++ Keyword . keys ( config . deps ) )
135
152
136
- if otp == true and app not in apps do
153
+ if is_app_otp ( app ) and app not in apps do
137
154
:otp
138
155
else
139
156
:ex_doc
140
157
end
141
158
end
142
159
end
143
160
144
- defp app_info ( module ) do
145
- case :code . which ( module ) do
146
- :preloaded ->
147
- { true , :erts }
148
-
149
- maybe_path ->
150
- otp? = is_list ( maybe_path ) and List . starts_with? ( maybe_path , :code . lib_dir ( ) )
151
-
152
- app =
153
- case :application . get_application ( module ) do
154
- { :ok , app } ->
155
- app
156
-
157
- _ ->
158
- with true <- is_list ( maybe_path ) ,
159
- [ _ , "ebin" , app , "lib" | _ ] <- maybe_path |> Path . split ( ) |> Enum . reverse ( ) do
160
- String . split ( app , "-" ) |> Enum . at ( 0 ) |> String . to_atom ( )
161
- else
162
- _ -> nil
163
- end
164
- end
165
-
166
- { otp? , app }
167
- end
161
+ defp is_app_otp ( app ) do
162
+ maybe_lib_dir_path = :code . lib_dir ( app )
163
+ is_list ( maybe_lib_dir_path ) and List . starts_with? ( maybe_lib_dir_path , :code . root_dir ( ) )
168
164
end
169
165
170
166
def maybe_warn ( config , ref , visibility , metadata ) do
@@ -302,16 +298,27 @@ defmodule ExDoc.Autolink do
302
298
{ extra , "#" <> anchor }
303
299
end
304
300
301
+ app = String . to_atom ( app )
302
+
305
303
config . deps
306
- |> Keyword . get_lazy ( String . to_atom ( app ) , fn ->
307
- maybe_warn (
308
- config ,
309
- "documentation references \" e:#{ string } \" but #{ app } cannot be found in deps." ,
310
- nil ,
311
- % { }
312
- )
313
-
314
- @ hexdocs <> "#{ app } "
304
+ |> Keyword . get_lazy ( app , fn ->
305
+ if Application . ensure_loaded ( app ) != :ok do
306
+ maybe_warn (
307
+ config ,
308
+ "documentation references \" e:#{ string } \" but #{ app } cannot be found." ,
309
+ nil ,
310
+ % { }
311
+ )
312
+ end
313
+
314
+ prefix =
315
+ cond do
316
+ app in config . apps -> ""
317
+ is_app_otp ( app ) -> @ otpappdocs
318
+ true -> @ hexdocs
319
+ end
320
+
321
+ prefix <> "#{ app } "
315
322
end )
316
323
|> String . trim_trailing ( "/" )
317
324
|> Kernel . <> ( "/" <> convert_extra_extension ( extra , config ) <> anchor )
0 commit comments