Skip to content

Commit

Permalink
Use async to load the module when starting lexical
Browse files Browse the repository at this point in the history
async has no effect on other features, and `Code.ensure_all_loaded` is a faster way of loading
  • Loading branch information
scottming committed Oct 30, 2023
1 parent 990fc9f commit f9a3152
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions apps/server/lib/lexical/server/boot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ defmodule Lexical.Server.Boot do
Packaging will ensure that config.exs and runtime.exs will be visible to the `:code` module
"""

alias Future.Code
alias Lexical.VM.Versions
require Logger

Expand All @@ -21,8 +23,6 @@ defmodule Lexical.Server.Boot do
load_config()
Application.ensure_all_started(:logger)

Enum.each(@dep_apps, &load_app_modules/1)

case detect_errors() do
[] ->
:ok
Expand All @@ -34,6 +34,12 @@ defmodule Lexical.Server.Boot do
end

Application.ensure_all_started(:server)

Task.async(fn ->
# credo:disable-for-next-line Credo.Check.Design.TagTODO
# TODO: When autocompletion no longer relies on ElixirSense, delete this loading logic.
Enum.each(@dep_apps, &load_app_modules/1)
end)
end

@doc false
Expand Down Expand Up @@ -79,7 +85,7 @@ defmodule Lexical.Server.Boot do
Application.ensure_loaded(app_name)

with {:ok, modules} <- :application.get_key(app_name, :modules) do
Enum.each(modules, &Code.ensure_loaded!/1)
Code.ensure_all_loaded!(modules)
end
end

Expand Down

0 comments on commit f9a3152

Please sign in to comment.