diff --git a/apps/language_server/lib/language_server/build.ex b/apps/language_server/lib/language_server/build.ex index a28346ce3..4982c630b 100644 --- a/apps/language_server/lib/language_server/build.ex +++ b/apps/language_server/lib/language_server/build.ex @@ -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) @@ -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) @@ -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} -> @@ -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", @@ -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} diff --git a/apps/language_server/lib/language_server/server.ex b/apps/language_server/lib/language_server/server.ex index 58b458761..5c915deaf 100644 --- a/apps/language_server/lib/language_server/server.ex +++ b/apps/language_server/lib/language_server/server.ex @@ -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, @@ -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 @@ -1337,7 +1339,7 @@ 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 @@ -1345,7 +1347,8 @@ defmodule ElixirLS.LanguageServer.Server do 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} = @@ -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 @@ -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 @@ -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) diff --git a/apps/language_server/lib/language_server/tracer.ex b/apps/language_server/lib/language_server/tracer.ex index 2b52c53bc..6794c34e0 100644 --- a/apps/language_server/lib/language_server/tracer.ex +++ b/apps/language_server/lib/language_server/tracer.ex @@ -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 diff --git a/apps/language_server/test/server_test.exs b/apps/language_server/test/server_test.exs index 791857ad5..2dd54cfe6 100644 --- a/apps/language_server/test/server_test.exs +++ b/apps/language_server/test/server_test.exs @@ -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 }