Skip to content

Commit

Permalink
Vendor erlex, erl2ex, unload not needed apps (#989)
Browse files Browse the repository at this point in the history
* update dialyxir to 1.4.1

vendor erlex

* vendor erl2ex

lock path_glob

* unload and remove not wanted apps from code path

* remove unloaded apps from code path
  • Loading branch information
lukaszsamson committed Sep 27, 2023
1 parent bf60d17 commit c25e22d
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 23 deletions.
16 changes: 14 additions & 2 deletions apps/elixir_ls_debugger/lib/debugger/cli.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirLS.Debugger.CLI do
alias ElixirLS.Utils
alias ElixirLS.Utils.{WireProtocol, Launch}
alias ElixirLS.Debugger.{Output, Server}

Expand Down Expand Up @@ -32,15 +33,26 @@ defmodule ElixirLS.Debugger.CLI do

Launch.limit_num_schedulers()
warn_if_unsupported_version()

Launch.unload_not_needed_apps([
:nimble_parsec,
:mix_task_archive_deps,
:language_server,
:dialyxir_vendored,
:path_glob_vendored,
:erlex_vendored,
:erl2ex_vendored
])

WireProtocol.stream_packets(&Server.receive_packet/1)
end

defp warn_if_unsupported_version do
with {:error, message} <- ElixirLS.Utils.MinimumVersion.check_elixir_version() do
with {:error, message} <- Utils.MinimumVersion.check_elixir_version() do
Output.debugger_important("WARNING: " <> message)
end

with {:error, message} <- ElixirLS.Utils.MinimumVersion.check_otp_version() do
with {:error, message} <- Utils.MinimumVersion.check_otp_version() do
Output.debugger_important("WARNING: " <> message)
end
end
Expand Down
22 changes: 22 additions & 0 deletions apps/elixir_ls_utils/lib/launch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,26 @@ defmodule ElixirLS.Utils.Launch do
raise Mix.NoTaskError, task: task
end
end

def unload_not_needed_apps(apps) do
for app <- apps do
modules =
case :application.get_key(app, :modules) do
{:ok, modules} -> modules
_ -> []
end

for module <- modules do
:code.purge(module)
:code.delete(module)
end

lib_dir = :code.lib_dir(app)
Application.unload(app)

if is_list(lib_dir) do
:code.del_path(:filename.join(lib_dir, ~c"ebin"))
end
end
end
end
4 changes: 2 additions & 2 deletions apps/elixir_ls_utils/test/support/mix_test.case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ defmodule ElixirLS.Utils.MixTest.Case do
statistex
patch
deep_merge
erlex
erlex_vendored
benchee
path_glob_vendored
dialyzer
dialyxir_vendored
erl2ex
erl2ex_vendored
jason_v
)a

Expand Down
28 changes: 20 additions & 8 deletions apps/language_server/lib/language_server/build.ex
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ defmodule ElixirLS.LanguageServer.Build do
end

defp purge_app(app) do
# TODO use hack with ets
modules =
case :application.get_key(app, :modules) do
{:ok, modules} -> modules
Expand All @@ -314,12 +313,27 @@ defmodule ElixirLS.LanguageServer.Build do
case Application.stop(app) do
:ok -> :ok
{:error, :not_started} -> :ok
{:error, error} -> Logger.error("Application.stop failed for #{app}: #{inspect(error)}")
{:error, error} -> Logger.warning("Application.stop failed for #{app}: #{inspect(error)}")
end

lib_dir = :code.lib_dir(app)

case Application.unload(app) do
:ok -> :ok
{:error, error} -> Logger.error("Application.unload failed for #{app}: #{inspect(error)}")
{:error, error} -> Logger.warning("Application.unload failed for #{app}: #{inspect(error)}")
end

if is_list(lib_dir) do
case :code.del_path(:filename.join(lib_dir, ~c"ebin")) do
true ->
:ok

false ->
:ok

{:error, reason} ->
Logger.warning("Unable to clean code path for #{app}: #{inspect(reason)}")
end
end
end

Expand Down Expand Up @@ -359,15 +373,13 @@ defmodule ElixirLS.LanguageServer.Build do
:language_server,
:elixir_ls_utils,
:elixir_sense,
:stream_data,
:jason_v,
:path_glob_vendored,
:dialyxir_vendored,
:erl2ex,
:patch,
:benchee
:erlex_vendored,
:erl2ex_vendored
] do
raise "Unloading #{app}"
raise "Unloading required #{app}"
end

for path <- Mix.Dep.load_paths(dep) do
Expand Down
2 changes: 2 additions & 0 deletions apps/language_server/lib/language_server/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ defmodule ElixirLS.LanguageServer.CLI do

Mix.shell(ElixirLS.LanguageServer.MixShell)

Launch.unload_not_needed_apps([:nimble_parsec, :mix_task_archive_deps, :elixir_ls_debugger])

WireProtocol.stream_packets(&JsonRpc.receive_packet/1)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule ElixirLS.LanguageServer.Providers.CodeLens.TypeSpec.ContractTranslator do
@moduledoc false
alias Erl2ex.Convert.{Context, ErlForms}
alias Erl2ex.Pipeline.{Parse, ModuleData, ExSpec}
alias Erl2exVendored.Convert.{Context, ErlForms}
alias Erl2exVendored.Pipeline.{Parse, ModuleData, ExSpec}

def translate_contract(fun, contract, is_macro, mod) do
# FIXME: Private module
Expand Down
1 change: 1 addition & 0 deletions apps/language_server/lib/language_server/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ defmodule ElixirLS.LanguageServer.Server do
case source_files[uri] do
%SourceFile{} = source_file ->
file = SourceFile.Path.from_uri(uri)

case parse_file(source_file.text, file) do
[] ->
Map.delete(state.parser_diagnostics, uri)
Expand Down
4 changes: 2 additions & 2 deletions apps/language_server/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ defmodule ElixirLS.LanguageServer.Mixfile do
[
{:elixir_ls_utils, in_umbrella: true},
{:elixir_sense, github: "elixir-lsp/elixir_sense", ref: @dep_versions[:elixir_sense]},
{:erl2ex, github: "dazuma/erl2ex"},
{:erl2ex_vendored, github: "elixir-lsp/erl2ex", ref: @dep_versions[:erl2ex_vendored]},
{:dialyxir_vendored,
github: "elixir-lsp/dialyxir", ref: @dep_versions[:dialyxir_vendored], runtime: false},
{:jason_v, github: "elixir-lsp/jason", ref: @dep_versions[:jason_v]},
{:stream_data, "~> 0.5", only: [:dev, :test], runtime: false},
{:path_glob_vendored, github: "elixir-lsp/path_glob", branch: "vendored"},
{:path_glob_vendored, github: "elixir-lsp/path_glob", ref: @dep_versions[:path_glob_vendored]},
{:patch, "~> 0.12.0", only: [:dev, :test], runtime: false},
{:benchee, "~> 1.0", only: :dev, runtime: false}
]
Expand Down
6 changes: 4 additions & 2 deletions dep_versions.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[
elixir_sense: "6a9f011ce5148b84de0fa1b142e38ccdbc26340c",
dialyxir_vendored: "7e908b4d760c7329046e0ee3076be9156cd784e1",
jason_v: "c81537e2a5e1acacb915cf339fe400357e3c2aaa"
dialyxir_vendored: "d50dcd7101c6ebd37b57b7ee4a7888d8cb634782",
jason_v: "c81537e2a5e1acacb915cf339fe400357e3c2aaa",
erl2ex_vendored: "073ac6b9a44282e718b6050c7b27cedf9217a12a",
path_glob_vendored: "965350dc41def7be4a70a23904195c733a2ecc84"
]
9 changes: 4 additions & 5 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
%{
"benchee": {:hex, :benchee, "1.1.0", "f3a43817209a92a1fade36ef36b86e1052627fd8934a8b937ac9ab3a76c43062", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}], "hexpm", "7da57d545003165a012b587077f6ba90b89210fd88074ce3c60ce239eb5e6d93"},
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
"dialyxir_vendored": {:git, "https://github.com/elixir-lsp/dialyxir.git", "7e908b4d760c7329046e0ee3076be9156cd784e1", [ref: "7e908b4d760c7329046e0ee3076be9156cd784e1"]},
"dialyxir_vendored": {:git, "https://github.com/elixir-lsp/dialyxir.git", "d50dcd7101c6ebd37b57b7ee4a7888d8cb634782", [ref: "d50dcd7101c6ebd37b57b7ee4a7888d8cb634782"]},
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "6a9f011ce5148b84de0fa1b142e38ccdbc26340c", [ref: "6a9f011ce5148b84de0fa1b142e38ccdbc26340c"]},
"erl2ex": {:git, "https://github.com/dazuma/erl2ex.git", "244c2d9ed5805ef4855a491d8616b8842fef7ca4", []},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"erl2ex_vendored": {:git, "https://github.com/elixir-lsp/erl2ex.git", "073ac6b9a44282e718b6050c7b27cedf9217a12a", [ref: "073ac6b9a44282e718b6050c7b27cedf9217a12a"]},
"erlex_vendored": {:git, "https://github.com/elixir-lsp/erlex.git", "82db0e82ee4896491bc26dec99f5d795f03ab9f4", [ref: "82db0e82ee4896491bc26dec99f5d795f03ab9f4"]},
"jason_v": {:git, "https://github.com/elixir-lsp/jason.git", "c81537e2a5e1acacb915cf339fe400357e3c2aaa", [ref: "c81537e2a5e1acacb915cf339fe400357e3c2aaa"]},
"jason_vendored": {:git, "https://github.com/elixir-lsp/jason.git", "e23c65b98411a3066ca73534b4aed1d23bcf0356", [branch: "vendored"]},
"mix_task_archive_deps": {:git, "https://github.com/elixir-lsp/mix_task_archive_deps.git", "30fa76221def649286835685fec5d151be83c354", []},
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
"patch": {:hex, :patch, "0.12.0", "2da8967d382bade20344a3e89d618bfba563b12d4ac93955468e830777f816b0", [:mix], [], "hexpm", "ffd0e9a7f2ad5054f37af84067ee88b1ad337308a1cb227e181e3967127b0235"},
"path_glob_vendored": {:git, "https://github.com/elixir-lsp/path_glob.git", "965350dc41def7be4a70a23904195c733a2ecc84", [branch: "vendored"]},
"path_glob_vendored": {:git, "https://github.com/elixir-lsp/path_glob.git", "965350dc41def7be4a70a23904195c733a2ecc84", [ref: "965350dc41def7be4a70a23904195c733a2ecc84"]},
"statistex": {:hex, :statistex, "1.0.0", "f3dc93f3c0c6c92e5f291704cf62b99b553253d7969e9a5fa713e5481cd858a5", [:mix], [], "hexpm", "ff9d8bee7035028ab4742ff52fc80a2aa35cece833cf5319009b52f1b5a86c27"},
"stream_data": {:hex, :stream_data, "0.5.0", "b27641e58941685c75b353577dc602c9d2c12292dd84babf506c2033cd97893e", [:mix], [], "hexpm", "012bd2eec069ada4db3411f9115ccafa38540a3c78c4c0349f151fc761b9e271"},
}

0 comments on commit c25e22d

Please sign in to comment.