From fae8f09b4c09b021e8ac54d0c5a6f283b4dce9ac Mon Sep 17 00:00:00 2001 From: robmckinnon Date: Mon, 20 Mar 2023 08:28:56 +0000 Subject: [PATCH] Handle string function name parameter --- .../language_server/experimental/code_mod/extract_function.ex | 3 +++ .../test/experimental/code_mod/extract_function_test.exs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/language_server/lib/language_server/experimental/code_mod/extract_function.ex b/apps/language_server/lib/language_server/experimental/code_mod/extract_function.ex index 4fe7e48f8..35176da0e 100644 --- a/apps/language_server/lib/language_server/experimental/code_mod/extract_function.ex +++ b/apps/language_server/lib/language_server/experimental/code_mod/extract_function.ex @@ -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} diff --git a/apps/language_server/test/experimental/code_mod/extract_function_test.exs b/apps/language_server/test/experimental/code_mod/extract_function_test.exs index 44d8099eb..4d8d95e3e 100644 --- a/apps/language_server/test/experimental/code_mod/extract_function_test.exs +++ b/apps/language_server/test/experimental/code_mod/extract_function_test.exs @@ -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 [