Skip to content

Commit

Permalink
reword title
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg committed Feb 24, 2024
1 parent 5bedeb0 commit 191dde0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
18 changes: 3 additions & 15 deletions lib/next_ls/extensions/elixir_extension/code_action/require.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ defmodule NextLS.ElixirExtension.CodeAction.Require do
with {:ok, require_module} <- get_edit(diagnostic.message),
{:ok, ast} <- parse_ast(text),
{:ok, defm} <- nearest_defmodule(ast, range),
{:ok, module_name} <- get_module_name(defm),
indentation <- get_indent(text, defm),
nearest <- find_nearest_node_for_require(defm),
range <- get_edit_range(nearest) do
[
%CodeAction{
title: "Add missing require in #{module_name}",
title: "Add missing require for #{require_module}",
diagnostics: [diagnostic],
edit: %WorkspaceEdit{
changes: %{
uri => [
%TextEdit{
new_text: indentation <> require_module,
new_text: indentation <> "require #{require_module}\n",
range: range
}
]
Expand Down Expand Up @@ -72,7 +71,7 @@ defmodule NextLS.ElixirExtension.CodeAction.Require do
@module_name ~r/require\s+([^\s]+)\s+before/
defp get_edit(message) do
case Regex.run(@module_name, message) do
[_, module] -> {:ok, "require #{module}\n"}
[_, module] -> {:ok, module}
_ -> {:error, "unable to find require"}
end
end
Expand Down Expand Up @@ -119,15 +118,4 @@ defmodule NextLS.ElixirExtension.CodeAction.Require do
context
end
end

defp get_module_name({:defmodule, _, [{:__aliases__, _, alias} | _rest]}) do
name =
alias
|> Module.concat()
|> Macro.to_string()

{:ok, name}
end

defp get_module_name(_), do: {:error, "expected defmodule ast"}
end
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule NextLS.ElixirExtension.RequireTest do
assert [code_action] = Require.new(diagnostic, text, uri)
assert is_struct(code_action, CodeAction)
assert [diagnostic] == code_action.diagnostics
assert code_action.title =~ "Test.Require"
assert code_action.title == "Add missing require for Logger"

assert %WorkspaceEdit{
changes: %{
Expand Down Expand Up @@ -83,7 +83,7 @@ defmodule NextLS.ElixirExtension.RequireTest do
assert [code_action] = Require.new(diagnostic, text, uri)
assert is_struct(code_action, CodeAction)
assert [diagnostic] == code_action.diagnostics
assert code_action.title =~ "Test.Require"
assert code_action.title == "Add missing require for Logger"

assert %WorkspaceEdit{
changes: %{
Expand Down Expand Up @@ -130,7 +130,7 @@ defmodule NextLS.ElixirExtension.RequireTest do
assert [code_action] = Require.new(diagnostic, text, uri)
assert is_struct(code_action, CodeAction)
assert [diagnostic] == code_action.diagnostics
assert code_action.title =~ "Test.Require"
assert code_action.title == "Add missing require for Logger"

assert %WorkspaceEdit{
changes: %{
Expand Down Expand Up @@ -186,7 +186,7 @@ defmodule NextLS.ElixirExtension.RequireTest do
assert [code_action] = Require.new(diagnostic, text, uri)
assert is_struct(code_action, CodeAction)
assert [diagnostic] == code_action.diagnostics
assert code_action.title =~ "Require"
assert code_action.title == "Add missing require for Logger"

assert %WorkspaceEdit{
changes: %{
Expand Down

0 comments on commit 191dde0

Please sign in to comment.