Skip to content

Commit

Permalink
fix(formatting): show message when it fails
Browse files Browse the repository at this point in the history
Shows error messages for well defined errors, but we don't receive
any signal that it failed for a plugin being missing, unfortunately.

Closes #463
  • Loading branch information
mhanberg committed May 22, 2024
1 parent 0b90ec3 commit 94751a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/next_ls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,16 @@ defmodule NextLS do

{:reply, nil, lsp}

_ ->
NextLS.Logger.warning(lsp.assigns.logger, "Failed to format the file: #{uri}")
e ->
case e do
{:ok, {:badrpc, {:EXIT, {%{description: description, file: file}, _stacktrace}}}} ->
NextLS.Logger.show_message(lsp.assigns.logger, :error, "Failed to format #{file}: #{description}")
NextLS.Logger.warning(lsp.assigns.logger, "Failed to format #{file}: #{description}")

_ ->
NextLS.Logger.show_message(lsp.assigns.logger, :error, "Failed to format #{uri}")
NextLS.Logger.warning(lsp.assigns.logger, "Failed to format #{uri}")
end

{:reply, nil, lsp}
end
Expand Down
6 changes: 6 additions & 0 deletions test/next_ls_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ defmodule NextLSTest do
}

assert_result 2, nil

assert_notification "window/showMessage", %{
"message" =>
"Failed to format /home/mitchell/src/next-ls/tmp/NextLSTest/test-formatting-gracefully-handles-files-with-syntax-errors-375a6619/my_proj/lib/foo/bar.ex: missing terminator: end",
"type" => 1
}
end

test "workspace symbols", %{client: client, cwd: cwd} = context do
Expand Down

0 comments on commit 94751a3

Please sign in to comment.