Skip to content

Commit 3ba3e50

Browse files
committed
fix crash when cwd is nil
1 parent d84a7c5 commit 3ba3e50

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

apps/language_server/lib/language_server/diagnostics.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
270270
}
271271
end
272272

273-
def exception_to_diagnostic(error, path \\ MixfileHelpers.mix_exs()) do
273+
def exception_to_diagnostic(error, path) do
274274
msg =
275275
case error do
276276
{:shutdown, 1} ->
@@ -282,7 +282,7 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
282282

283283
%Mix.Task.Compiler.Diagnostic{
284284
compiler_name: "ElixirLS",
285-
file: Path.absname(path),
285+
file: path,
286286
# 0 means unknown
287287
position: 0,
288288
message: msg,

apps/language_server/lib/language_server/server.ex

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,6 @@ defmodule ElixirLS.LanguageServer.Server do
311311
) do
312312
state = %{state | build_running?: false}
313313

314-
state =
315-
case reason do
316-
:normal -> state
317-
_ -> handle_build_result(:error, [Diagnostics.exception_to_diagnostic(reason)], state)
318-
end
319-
320314
# in case the build was interrupted make sure that cwd is reset to project dir
321315
case File.cd(state.project_dir) do
322316
:ok ->
@@ -330,6 +324,16 @@ defmodule ElixirLS.LanguageServer.Server do
330324
JsonRpc.show_message(:error, message)
331325
end
332326

327+
state =
328+
case reason do
329+
:normal ->
330+
state
331+
332+
_ ->
333+
path = Path.join(state.project_dir, MixfileHelpers.mix_exs())
334+
handle_build_result(:error, [Diagnostics.exception_to_diagnostic(reason, path)], state)
335+
end
336+
333337
if reason == :normal do
334338
WorkspaceSymbols.notify_build_complete()
335339
end

0 commit comments

Comments
 (0)