Skip to content

Commit 3eb9c10

Browse files
authored
feat: Etask projection (#119)
Closes #92
1 parent 27c488d commit 3eb9c10

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

lua/elixir/projectionist/init.lua

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
local M = {}
2+
if not vim.g.projectionist_transformations then
3+
vim.g.projectionist_transformations = vim.empty_dict()
4+
end
5+
6+
ElixirToolsProjectionistElixirModule = function(input)
7+
return input:gsub("(%.%l)", string.upper)
8+
end
9+
10+
vim.cmd([[
11+
function! g:projectionist_transformations.elixir_module(input, o) abort
12+
return v:lua.ElixirToolsProjectionistElixirModule(a:input, a:o)
13+
endfunction
14+
]])
215

316
local config = {
417
["mix.exs"] = {
@@ -139,10 +152,31 @@ local config = {
139152
type = "test",
140153
alternate = "lib/{}.ex",
141154
template = {
142-
"defmodule {camelcase|capitalize|dot}Test do",
155+
"defmodule {camelcase|capitalize|dot|elixir_module}Test do",
143156
" use ExUnit.Case, async: true",
144157
"",
145-
" alias {camelcase|capitalize|dot}",
158+
" alias {camelcase|capitalize|dot|elixir_module}",
159+
"end",
160+
},
161+
},
162+
["lib/mix/tasks/*.ex"] = {
163+
type = "task",
164+
alternate = "test/mix/tasks/{}_test.exs",
165+
template = {
166+
"defmodule Mix.Tasks.{camelcase|capitalize|dot|elixir_module} do",
167+
[[ use Mix.Task]],
168+
"",
169+
[[ @shortdoc "{}"]],
170+
"",
171+
[[ @moduledoc """]],
172+
[[ {}]],
173+
[[ """]],
174+
"",
175+
[[ @impl true]],
176+
[[ @doc false]],
177+
[[ def run(argv) do]],
178+
"",
179+
[[ end]],
146180
"end",
147181
},
148182
},

tests/projectionist_spec.lua

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,37 @@ describe("projectionist", function()
6565
{ "defmodule ProjectAWeb.UserLive do", " use ProjectAWeb, :live_view", "end" }
6666
)
6767
end)
68+
69+
it("Etask", function()
70+
vim.cmd.Etask("foo.bar")
71+
vim.cmd.write()
72+
73+
assert.are.same(vim.fn.readfile("lib/mix/tasks/foo.bar.ex"), {
74+
"defmodule Mix.Tasks.Foo.Bar do",
75+
[[ use Mix.Task]],
76+
"",
77+
[[ @shortdoc "foo.bar"]],
78+
"",
79+
[[ @moduledoc """]],
80+
[[ foo.bar]],
81+
[[ """]],
82+
"",
83+
[[ @impl true]],
84+
[[ @doc false]],
85+
[[ def run(argv) do]],
86+
"",
87+
[[ end]],
88+
"end",
89+
})
90+
91+
vim.cmd([[call feedkeys("1\<cr>", "t") | A | write]])
92+
93+
assert.are.same(vim.fn.readfile("test/mix/tasks/foo.bar_test.exs"), {
94+
"defmodule Mix.Tasks.Foo.BarTest do",
95+
[[ use ExUnit.Case, async: true]],
96+
"",
97+
[[ alias Mix.Tasks.Foo.Bar]],
98+
"end",
99+
})
100+
end)
68101
end)

0 commit comments

Comments
 (0)