Skip to content

Commit 529162e

Browse files
committed
optimise app retrieval
1 parent e3a1db3 commit 529162e

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

apps/language_server/lib/language_server/doc_links.ex

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,14 @@ defmodule ElixirLS.LanguageServer.DocLinks do
55

66
@hex_base_url "https://hexdocs.pm"
77

8-
defp get_erts_modules do
9-
{:ok, [[erlang_lib_dir]]} = :init.get_argument(:root)
10-
erts_version = :erlang.system_info(:version)
11-
erts_app_path = Path.join([erlang_lib_dir, "lib", "erts-#{erts_version}", "ebin", "erts.app"])
12-
13-
{:ok, [{:application, _, props}]} = :file.consult(erts_app_path)
14-
modules = Keyword.get(props, :modules)
15-
for module <- modules, into: %{}, do: {module, {:erts, erts_version}}
16-
end
17-
188
defp get_app(module) do
19-
module_to_app =
20-
for {app, _, vsn} <- Application.loaded_applications(),
21-
{:ok, app_modules} = :application.get_key(app, :modules),
22-
mod <- app_modules,
23-
into: %{},
24-
do: {mod, {app, vsn}}
25-
26-
module_to_app
27-
|> Map.merge(get_erts_modules())
28-
|> Map.get(module)
9+
with {:ok, app} <- :application.get_application(module),
10+
{:ok, vsn} <- :application.get_key(app, :vsn) do
11+
{app, vsn}
12+
else
13+
_ ->
14+
nil
15+
end
2916
end
3017

3118
def hex_docs_module_link(module) do

0 commit comments

Comments
 (0)