Skip to content

Commit 2bf42c8

Browse files
committed
fix: improve error handling for compiler diagnostics
1 parent 2b83c33 commit 2bf42c8

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

lib/next_ls/extensions/elixir_extension.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defmodule NextLS.ElixirExtension do
2424
end
2525

2626
@impl GenServer
27-
def handle_info({:compiler, diagnostics}, state) do
27+
def handle_info({:compiler, diagnostics}, state) when is_list(diagnostics) do
2828
DiagnosticCache.clear(state.cache, :elixir)
2929

3030
for d <- diagnostics do

lib/next_ls/runtime.ex

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ defmodule NextLS.Runtime do
120120
NextLS.Logger.log(logger, "The runtime for #{name} has successfully shutdown.")
121121

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

142142
_ ->
143143
:ok
@@ -192,15 +192,16 @@ defmodule NextLS.Runtime do
192192
def handle_call(:compile, from, %{node: node} = state) do
193193
task =
194194
Task.Supervisor.async_nolink(state.task_supervisor, fn ->
195-
{_, errors} = :rpc.call(node, :_next_ls_private_compiler, :compile, [])
195+
case :rpc.call(node, :_next_ls_private_compiler, :compile, []) do
196+
{:badrpc, error} ->
197+
NextLS.Logger.error(state.logger, {:badrpc, error})
196198

197-
Registry.dispatch(state.registry, :extensions, fn entries ->
198-
for {pid, _} <- entries do
199-
send(pid, {:compiler, errors})
200-
end
201-
end)
199+
{_, [_ | _] = diagnostics} ->
200+
dispatch_to_extensions(state, {:compiler, diagnostics})
202201

203-
errors
202+
_ ->
203+
:ok
204+
end
204205
end)
205206

206207
{:noreply, %{state | compiler_ref: %{task.ref => from}}}
@@ -248,4 +249,10 @@ defmodule NextLS.Runtime do
248249
true
249250
end
250251
end
252+
253+
defp dispatch_to_extensions(state, message) do
254+
Registry.dispatch(state.registry, :extensions, fn entries ->
255+
for {pid, _} <- entries, do: send(pid, message)
256+
end)
257+
end
251258
end

0 commit comments

Comments
 (0)