Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(manipulatePipes): avoid crashing upon errors #576

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipes do
}) do
{:ok, nil}
else
{:error, reason} ->
{:error, reason}
{:error, :pipe_not_found} ->
{:error, :parse_error, "Pipe operator not found at cursor"}

{:error, :function_call_not_found} ->
{:error, :parse_error, "Function call not found at cursor"}

{:error, :invalid_code} ->
{:error, :parse_error, "Malformed code"}

error ->
{:error, :server_error,
"cannot execute pipe conversion, workspace/applyEdit returned #{inspect(error)}"}
"Cannot execute pipe conversion, workspace/applyEdit returned #{inspect(error)}"}
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d
) == edited_text
end

test "can pipe remote calls with ulti-line args" do
test "can pipe remote calls with multi-line args" do
{:ok, _} =
JsonRpcMock.start_link(success_reply: {:ok, %{"applied" => true}}, test_pid: self())

Expand Down Expand Up @@ -456,7 +456,6 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d
assert edited_text == expected_text
end

# Broken
test "to_pipe_at_cursor at end of function (with another function after)" do
text = """
defmodule Demo do
Expand Down Expand Up @@ -562,6 +561,38 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d
) == edited_text
end

test "converts function_call_not_found to 3-tuple" do
{:ok, _} =
JsonRpcMock.start_link(success_reply: {:ok, %{"applied" => true}}, test_pid: self())

uri = "file:/some_file.ex"

text = """
test = 1
%{
q:
if(is_nil(test),
do: max(test, is_nil(test)),
else: []
)
}
"""

assert_never_raises(text, uri, "toPipe")

assert {:error, :parse_error, "Function call not found at cursor"} =
ManipulatePipes.execute(
["toPipe", uri, 4, 13],
%Server{
source_files: %{
uri => %SourceFile{
text: text
}
}
}
)
end

for {line_sep, test_name_suffix} <- [{"\r\n", "\\r\\n"}, {"\n", "\\n"}] do
test "can pipe correctly when the line separator is #{test_name_suffix}" do
{:ok, _} =
Expand Down Expand Up @@ -1140,7 +1171,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d

assert_never_raises(text, uri, "fromPipe")

assert {:error, :pipe_not_found} =
assert {:error, :parse_error, "Pipe operator not found at cursor"} =
ManipulatePipes.execute(
["fromPipe", uri, 4, 16],
%Server{
Expand Down