Skip to content

Commit

Permalink
attempt to fix errors on <= 1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Nov 28, 2023
1 parent adb4f79 commit 7edf428
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
13 changes: 11 additions & 2 deletions apps/language_server/lib/language_server/build.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ defmodule ElixirLS.LanguageServer.Build do
case deps_result do
:ok ->
if Keyword.get(opts, :compile?) do
{status, compile_diagnostics} = run_mix_compile()
{status, compile_diagnostics} = run_mix_compile(Keyword.get(opts, :force?, false))

compile_diagnostics =
Diagnostics.normalize(compile_diagnostics, root_path, mixfile)
Expand Down Expand Up @@ -128,6 +128,7 @@ defmodule ElixirLS.LanguageServer.Build do
JsonRpc.telemetry("build", %{"elixir_ls.build_result" => result}, %{
"elixir_ls.build_time" => div(us, 1000)
})
IO.warn("Releasing build lock")
end)
end)

Expand Down Expand Up @@ -265,6 +266,7 @@ defmodule ElixirLS.LanguageServer.Build do
Code.put_compiler_option(:no_warn_undefined, :all)

# We can get diagnostics if Mixfile fails to load
IO.warn("Building mixfile #{mixfile}")
{mixfile_status, mixfile_diagnostics} =
case Kernel.ParallelCompiler.compile([mixfile]) do
{:ok, _, warnings} ->
Expand Down Expand Up @@ -351,7 +353,7 @@ defmodule ElixirLS.LanguageServer.Build do
end
end

defp run_mix_compile do
defp run_mix_compile(force?) do
opts = [
"--return-errors",
"--ignore-module-conflict",
Expand All @@ -365,6 +367,13 @@ defmodule ElixirLS.LanguageServer.Build do
opts ++ ["--all-warnings"]
end

opts =
if force? do
opts ++ ["--force"]
else
opts
end

case Mix.Task.run("compile", opts) do
{status, diagnostics} when status in [:ok, :error, :noop] and is_list(diagnostics) ->
{status, diagnostics}
Expand Down
13 changes: 8 additions & 5 deletions apps/language_server/lib/language_server/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ defmodule ElixirLS.LanguageServer.Server do
build_diagnostics: [],
dialyzer_diagnostics: [],
needs_build?: false,
full_build_done?: false,
build_running?: false,
analysis_ready?: false,
received_shutdown?: false,
Expand Down Expand Up @@ -316,6 +317,7 @@ defmodule ElixirLS.LanguageServer.Server do
%__MODULE__{build_ref: ref, build_running?: true} = state
) do
state = %{state | build_running?: false}
IO.warn("Build end reason: #{inspect(reason)}")

# in case the build was interrupted make sure that cwd is reset to project dir
case File.cd(state.project_dir) do
Expand Down Expand Up @@ -1337,15 +1339,16 @@ defmodule ElixirLS.LanguageServer.Server do

# Build

defp trigger_build(state = %__MODULE__{project_dir: project_dir}) do
defp trigger_build(state = %__MODULE__{project_dir: project_dir, full_build_done?: full_build_done?}) do
cond do
not is_binary(project_dir) ->
state

not state.build_running? ->
opts = [
fetch_deps?: Map.get(state.settings || %{}, "fetchDeps", false),
compile?: Map.get(state.settings || %{}, "autoBuild", true)
compile?: Map.get(state.settings || %{}, "autoBuild", true),
force?: not full_build_done?
]

{_pid, build_ref} =
Expand Down Expand Up @@ -1459,7 +1462,7 @@ defmodule ElixirLS.LanguageServer.Server do
state.project_dir
)

state
%{state | full_build_done?: if(status == :ok, do: true, else: state.full_build_done?)}
end

defp handle_dialyzer_result(diagnostics, build_ref, state = %__MODULE__{}) do
Expand Down Expand Up @@ -1689,7 +1692,7 @@ defmodule ElixirLS.LanguageServer.Server do

add_watched_extensions(state.server_instance_id, additional_watched_extensions)

maybe_rebuild(state)
# maybe_rebuild(state)
state = create_gitignore(state)

if state.mix_project? do
Expand Down Expand Up @@ -2153,7 +2156,7 @@ defmodule ElixirLS.LanguageServer.Server do
rescue
e ->
message =
"Unable to reload project: #{Exception.message(e)}"
"Unable to reload project: #{Exception.format(:error, e, __STACKTRACE__)}"

Logger.error(message)

Expand Down
4 changes: 3 additions & 1 deletion apps/language_server/lib/language_server/tracer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ defmodule ElixirLS.LanguageServer.Tracer do
{version, ""} <- Integer.parse(text) do
version
else
_ -> nil
other ->
IO.warn("Manifest: #{inspect(other)}")
nil
end
end

Expand Down
2 changes: 1 addition & 1 deletion apps/language_server/test/server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ defmodule ElixirLS.LanguageServer.ServerTest do
"uri" => ^error_file,
"diagnostics" => [
%{
"message" => "(CompileError) undefined function does_not_exist" <> _,
"message" => "** (CompileError) lib/has_error.ex:4: undefined function does_not_exist" <> _,
"range" => %{"end" => %{"line" => 3}, "start" => %{"line" => 3}},
"severity" => 1
}
Expand Down

0 comments on commit 7edf428

Please sign in to comment.