Skip to content

Commit

Permalink
remove load_all_applications (#725)
Browse files Browse the repository at this point in the history
since elixir 1.11 mix compile loads applications by default
  • Loading branch information
lukaszsamson committed Sep 10, 2022
1 parent caad581 commit 6c1833c
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 44 deletions.
31 changes: 0 additions & 31 deletions apps/language_server/lib/language_server/build.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ defmodule ElixirLS.LanguageServer.Build do
purge_consolidated_protocols()
{status, diagnostics} = compile()

if status in [:ok, :noop] and Keyword.get(opts, :load_all_mix_applications?) do
load_all_mix_applications()
end

diagnostics = Diagnostics.normalize(diagnostics, root_path)
Server.build_finished(parent, {status, mixfile_diagnostics ++ diagnostics})

Expand Down Expand Up @@ -108,33 +104,6 @@ defmodule ElixirLS.LanguageServer.Build do
end
end

# TODO It looks like that function is no longer needed on elixir >= 1.11
# it was added in https://github.com/elixir-lsp/elixir-ls/pull/227
# removing it doesn't break tests and I'm not able to reproduce
# https://github.com/elixir-lsp/elixir-ls/issues/209 on recent elixir (1.13)
def load_all_mix_applications do
apps =
cond do
Mix.Project.umbrella?() ->
Mix.Project.apps_paths() |> Map.keys()

app = Keyword.get(Mix.Project.config(), :app) ->
[app]

true ->
[]
end

Enum.each(apps, fn app ->
true = Code.prepend_path(Path.join(Mix.Project.build_path(), "lib/#{app}/ebin"))

case Application.load(app) do
:ok -> :ok
{:error, {:already_loaded, _}} -> :ok
end
end)
end

defp compile do
case Mix.Task.run("compile", ["--return-errors", "--ignore-module-conflict"]) do
{status, diagnostics} when status in [:ok, :error, :noop] and is_list(diagnostics) ->
Expand Down
12 changes: 3 additions & 9 deletions apps/language_server/lib/language_server/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ defmodule ElixirLS.LanguageServer.Server do
build_diagnostics: [],
dialyzer_diagnostics: [],
needs_build?: false,
load_all_mix_applications?: false,
build_running?: false,
analysis_ready?: false,
received_shutdown?: false,
Expand Down Expand Up @@ -923,19 +922,14 @@ defmodule ElixirLS.LanguageServer.Server do
not state.build_running? ->
fetch_deps? = Map.get(state.settings || %{}, "fetchDeps", false)

{_pid, build_ref} =
Build.build(self(), project_dir,
fetch_deps?: fetch_deps?,
load_all_mix_applications?: state.load_all_mix_applications?
)
{_pid, build_ref} = Build.build(self(), project_dir, fetch_deps?: fetch_deps?)

%__MODULE__{
state
| build_ref: build_ref,
needs_build?: false,
build_running?: true,
analysis_ready?: false,
load_all_mix_applications?: false
analysis_ready?: false
}

true ->
Expand Down Expand Up @@ -1217,7 +1211,7 @@ defmodule ElixirLS.LanguageServer.Server do

is_nil(prev_project_dir) ->
File.cd!(project_dir)
Map.merge(state, %{project_dir: File.cwd!(), load_all_mix_applications?: true})
%{state | project_dir: File.cwd!()}

prev_project_dir != project_dir ->
JsonRpc.show_message(
Expand Down
2 changes: 0 additions & 2 deletions apps/language_server/test/providers/code_lens/test_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ defmodule ElixirLS.LanguageServer.Providers.CodeLens.TestTest do
@project_dir "/project"

setup context do
ElixirLS.LanguageServer.Build.load_all_mix_applications()

unless context[:skip_server] do
server = ElixirLS.LanguageServer.Test.ServerTestHelpers.start_server()

Expand Down
2 changes: 0 additions & 2 deletions apps/language_server/test/providers/completion_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ defmodule ElixirLS.LanguageServer.Providers.CompletionTest do
}

setup context do
ElixirLS.LanguageServer.Build.load_all_mix_applications()

unless context[:skip_server] do
server = ElixirLS.LanguageServer.Test.ServerTestHelpers.start_server()

Expand Down

0 comments on commit 6c1833c

Please sign in to comment.