Skip to content

Commit

Permalink
Handle string function name parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
robmckinnon committed May 3, 2023
1 parent ce2cd59 commit fae8f09
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ defmodule ElixirLS.LanguageServer.Experimental.CodeMod.ExtractFunction do
Return zipper containing AST with extracted function.
"""
def extract_function(zipper, start_line, end_line, function_name) do
function_name =
if is_binary(function_name), do: String.to_atom(function_name), else: function_name

{quoted_after_extract, acc} = extract_lines(zipper, start_line, end_line, function_name)
if Enum.empty?(acc.lines) do
{:error, :not_extractable}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule ElixirLS.LanguageServer.Experimental.CodeMod.ExtractFunctionTest do
describe "extract_function" do
@tag no: 1
test "extract one line to function", %{quoted: quoted} do
zipper = ExtractFunction.extract_function(Z.zip(quoted), 3, 3, :bar)
zipper = ExtractFunction.extract_function(Z.zip(quoted), 3, 3, "bar")
source = Sourceror.to_string(zipper)

assert [
Expand Down

0 comments on commit fae8f09

Please sign in to comment.