Skip to content

Commit

Permalink
fix: improve error handling for compiler diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
zachallaun committed Aug 11, 2023
1 parent 2b83c33 commit a972a4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/next_ls/extensions/elixir_extension.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule NextLS.ElixirExtension do
end

@impl GenServer
def handle_info({:compiler, diagnostics}, state) do
def handle_info({:compiler, diagnostics}, state) when is_list(diagnostics) do
DiagnosticCache.clear(state.cache, :elixir)

for d <- diagnostics do
Expand Down
27 changes: 17 additions & 10 deletions lib/next_ls/runtime.ex
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ defmodule NextLS.Runtime do
NextLS.Logger.log(logger, "The runtime for #{name} has successfully shutdown.")

reason ->
NextLS.Logger.error(logger, "The runtime for #{name} has crashed with reason: #{reason}.")
NextLS.Logger.error(logger, "The runtime for #{name} has crashed with reason: #{inspect(reason)}.")
end
end
end)
Expand All @@ -136,8 +136,8 @@ defmodule NextLS.Runtime do
|> Path.join("monkey/_next_ls_private_compiler.ex")
|> then(&:rpc.call(node, Code, :compile_file, [&1]))
|> tap(fn
{:badrpc, :EXIT, {error, _}} ->
NextLS.Logger.error(logger, error)
{:badrpc, error} ->
NextLS.Logger.error(logger, {:badrpc, error})

_ ->
:ok
Expand Down Expand Up @@ -192,15 +192,22 @@ defmodule NextLS.Runtime do
def handle_call(:compile, from, %{node: node} = state) do
task =
Task.Supervisor.async_nolink(state.task_supervisor, fn ->
{_, errors} = :rpc.call(node, :_next_ls_private_compiler, :compile, [])
case :rpc.call(node, :_next_ls_private_compiler, :compile, []) do
{:badrpc, error} ->
NextLS.Logger.error(state.logger, {:badrpc, error})
[]

Registry.dispatch(state.registry, :extensions, fn entries ->
for {pid, _} <- entries do
send(pid, {:compiler, errors})
end
end)
{_, diagnostics} when is_list(diagnostics) ->
Registry.dispatch(state.registry, :extensions, fn entries ->
for {pid, _} <- entries, do: send(pid, {:compiler, diagnostics})
end)

errors
diagnostics

unknown ->
NextLS.Logger.warning(state.logger, "Unexpected compiler response: #{inspect(unknown)}")
[]
end
end)

{:noreply, %{state | compiler_ref: %{task.ref => from}}}
Expand Down

0 comments on commit a972a4f

Please sign in to comment.