diff --git a/lua/elixir/projectionist/init.lua b/lua/elixir/projectionist/init.lua index 993b2de6..6a93d1ec 100644 --- a/lua/elixir/projectionist/init.lua +++ b/lua/elixir/projectionist/init.lua @@ -1,4 +1,17 @@ local M = {} +if not vim.g.projectionist_transformations then + vim.g.projectionist_transformations = vim.empty_dict() +end + +ElixirToolsProjectionistElixirModule = function(input) + return input:gsub("(%.%l)", string.upper) +end + +vim.cmd([[ +function! g:projectionist_transformations.elixir_module(input, o) abort + return v:lua.ElixirToolsProjectionistElixirModule(a:input, a:o) +endfunction +]]) local config = { ["mix.exs"] = { @@ -139,10 +152,31 @@ local config = { type = "test", alternate = "lib/{}.ex", template = { - "defmodule {camelcase|capitalize|dot}Test do", + "defmodule {camelcase|capitalize|dot|elixir_module}Test do", " use ExUnit.Case, async: true", "", - " alias {camelcase|capitalize|dot}", + " alias {camelcase|capitalize|dot|elixir_module}", + "end", + }, + }, + ["lib/mix/tasks/*.ex"] = { + type = "task", + alternate = "test/mix/tasks/{}_test.exs", + template = { + "defmodule Mix.Tasks.{camelcase|capitalize|dot|elixir_module} do", + [[ use Mix.Task]], + "", + [[ @shortdoc "{}"]], + "", + [[ @moduledoc """]], + [[ {}]], + [[ """]], + "", + [[ @impl true]], + [[ @doc false]], + [[ def run(argv) do]], + "", + [[ end]], "end", }, }, diff --git a/tests/projectionist_spec.lua b/tests/projectionist_spec.lua index 2a5c567d..a1246c03 100644 --- a/tests/projectionist_spec.lua +++ b/tests/projectionist_spec.lua @@ -65,4 +65,37 @@ describe("projectionist", function() { "defmodule ProjectAWeb.UserLive do", " use ProjectAWeb, :live_view", "end" } ) end) + + it("Etask", function() + vim.cmd.Etask("foo.bar") + vim.cmd.write() + + assert.are.same(vim.fn.readfile("lib/mix/tasks/foo.bar.ex"), { + "defmodule Mix.Tasks.Foo.Bar do", + [[ use Mix.Task]], + "", + [[ @shortdoc "foo.bar"]], + "", + [[ @moduledoc """]], + [[ foo.bar]], + [[ """]], + "", + [[ @impl true]], + [[ @doc false]], + [[ def run(argv) do]], + "", + [[ end]], + "end", + }) + + vim.cmd([[call feedkeys("1\", "t") | A | write]]) + + assert.are.same(vim.fn.readfile("test/mix/tasks/foo.bar_test.exs"), { + "defmodule Mix.Tasks.Foo.BarTest do", + [[ use ExUnit.Case, async: true]], + "", + [[ alias Mix.Tasks.Foo.Bar]], + "end", + }) + end) end)