Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Oct 31, 2023
1 parent e31d2c9 commit 7c0ebda
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 50 deletions.
93 changes: 56 additions & 37 deletions apps/language_server/lib/language_server/build.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,43 @@ defmodule ElixirLS.LanguageServer.Build do

case reload_project(mixfile) do
{:ok, mixfile_diagnostics} ->
{deps_result, deps_raw_diagnostics} = with_diagnostics([log: true], fn ->
try do
# this call can raise
current_deps = Mix.Dep.load_on_environment([])

purge_changed_deps(current_deps, cached_deps)

if Keyword.get(opts, :fetch_deps?) and current_deps != cached_deps do
fetch_deps(current_deps)
{deps_result, deps_raw_diagnostics} =
with_diagnostics([log: true], fn ->
try do
# this call can raise
current_deps = Mix.Dep.load_on_environment([])

purge_changed_deps(current_deps, cached_deps)

if Keyword.get(opts, :fetch_deps?) and current_deps != cached_deps do
fetch_deps(current_deps)
end

state = %{
get: Mix.Project.get(),
# project_file: Mix.Project.project_file(),
config: Mix.Project.config(),
# config_files: Mix.Project.config_files(),
config_mtime: Mix.Project.config_mtime(),
umbrella?: Mix.Project.umbrella?(),
apps_paths: Mix.Project.apps_paths(),
# deps_path: Mix.Project.deps_path(),
# deps_apps: Mix.Project.deps_apps(),
# deps_scms: Mix.Project.deps_scms(),
deps_paths: Mix.Project.deps_paths(),
# build_path: Mix.Project.build_path(),
manifest_path: Mix.Project.manifest_path()
}

ElixirLS.LanguageServer.MixProject.store(state)

:ok
catch
kind, err ->
{payload, stacktrace} = Exception.blame(kind, err, __STACKTRACE__)
{:error, kind, payload, stacktrace}
end

state = %{
get: Mix.Project.get(),
# project_file: Mix.Project.project_file(),
config: Mix.Project.config(),
# config_files: Mix.Project.config_files(),
config_mtime: Mix.Project.config_mtime(),
umbrella?: Mix.Project.umbrella?(),
apps_paths: Mix.Project.apps_paths(),
# deps_path: Mix.Project.deps_path(),
# deps_apps: Mix.Project.deps_apps(),
# deps_scms: Mix.Project.deps_scms(),
deps_paths: Mix.Project.deps_paths(),
# build_path: Mix.Project.build_path(),
manifest_path: Mix.Project.manifest_path()
}
ElixirLS.LanguageServer.MixProject.store(state)

:ok
catch
kind, err ->
{payload, stacktrace} = Exception.blame(kind, err, __STACKTRACE__)
{:error, kind, payload, stacktrace}
end
end)
end)

deps_diagnostics =
deps_raw_diagnostics
Expand All @@ -62,15 +64,32 @@ defmodule ElixirLS.LanguageServer.Build do
{status, compile_diagnostics} = run_mix_compile()

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

Server.build_finished(
parent,
{status, mixfile_diagnostics ++ deps_diagnostics ++ compile_diagnostics}
)

:"mix_compile_#{status}"
else
Server.build_finished(parent, {:ok, mixfile_diagnostics ++ deps_diagnostics})
Server.build_finished(
parent,
{:ok, mixfile_diagnostics ++ deps_diagnostics}
)

:mix_compile_disabled
end

{:error, kind, err, stacktrace} ->
# TODO get path from exception message
Server.build_finished(parent, {:error, mixfile_diagnostics ++ deps_diagnostics ++ [Diagnostics.error_to_diagnostic(kind, err, stacktrace, mixfile)]})
Server.build_finished(
parent,
{:error,
mixfile_diagnostics ++
deps_diagnostics ++
[Diagnostics.error_to_diagnostic(kind, err, stacktrace, mixfile)]}
)

:deps_error
end

Expand Down
16 changes: 12 additions & 4 deletions apps/language_server/lib/language_server/dialyzer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,24 @@ defmodule ElixirLS.LanguageServer.Dialyzer do
{:ok, _} ->
Logger.info("Beam file #{inspect(beam_path)} removed")
:ok

rm_error ->
Logger.warning("Unable to remove beam file #{inspect(beam_path)}: #{inspect(rm_error)}")
Logger.warning(
"Unable to remove beam file #{inspect(beam_path)}: #{inspect(rm_error)}"
)

JsonRpc.show_message(
:error,
"ElixirLS Dialyzer is unable to process #{inspect(beam_path)}. Please remove it manually")
"ElixirLS Dialyzer is unable to process #{inspect(beam_path)}. Please remove it manually"
)
end

_ ->
JsonRpc.show_message(
:error,
"ElixirLS Dialyzer is unable to process one of the beam files. Please remove .elixir_ls/dialyzer* directory manually")
:error,
"ElixirLS Dialyzer is unable to process one of the beam files. Please remove .elixir_ls/dialyzer* directory manually"
)

:ok
end

Expand Down
24 changes: 15 additions & 9 deletions apps/language_server/lib/language_server/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,7 @@ defmodule ElixirLS.LanguageServer.Server do
{:ok, cwd} ->
if Path.absname(cwd) == Path.absname(project_dir) do
mixfile = Path.absname(MixfileHelpers.mix_exs())

case Build.reload_project(mixfile) do
{:ok, _} ->
Build.clean(true)
Expand All @@ -1872,9 +1873,12 @@ defmodule ElixirLS.LanguageServer.Server do
:ok
end
else
message = "Unable to reload project: cwd #{inspect(cwd)} is not project dir #{project_dir}"
message =
"Unable to reload project: cwd #{inspect(cwd)} is not project dir #{project_dir}"

Logger.error(message)
JsonRpc.telemetry(

JsonRpc.telemetry(
"lsp_server_error",
%{
"elixir_ls.lsp_process" => inspect(__MODULE__),
Expand All @@ -1883,17 +1887,19 @@ defmodule ElixirLS.LanguageServer.Server do
%{}
)
end

{:error, reason} ->
message = "Unable to reload project: #{inspect(reason)}"
Logger.error(message)

JsonRpc.telemetry(
"lsp_server_error",
%{
"elixir_ls.lsp_process" => inspect(__MODULE__),
"elixir_ls.lsp_server_error" => message
},
%{}
)
"lsp_server_error",
%{
"elixir_ls.lsp_process" => inspect(__MODULE__),
"elixir_ls.lsp_server_error" => message
},
%{}
)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions apps/language_server/test/providers/formatting_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ defmodule ElixirLS.LanguageServer.Providers.FormattingTest do
# build_path: Mix.Project.build_path(),
manifest_path: Mix.Project.manifest_path()
}

MixProject.store(state)
end
end

0 comments on commit 7c0ebda

Please sign in to comment.