Skip to content

Commit baede6c

Browse files
chore: Do not use deprecated vim.tbl_flatten() (#36)
* Do not use deprecated vim.tbl_flatten() * Format code --------- Co-authored-by: Jhon Pedroza <jhon@pedroza.me>
1 parent bc8c073 commit baede6c

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ require("neotest").setup({
5353
-- Must be a function that receives the mix command as a table, to return a dynamic value
5454
-- Default: function(cmd) return cmd end
5555
post_process_command = function(cmd)
56-
return vim.tbl_flatten({{"env", "FOO=bar"}, cmd})
56+
return vim.iter({{"env", "FOO=bar"}, cmd}):flatten():totable()
5757
end,
5858
-- Delays writes so that results are updated at most every given milliseconds
5959
-- Decreasing this number improves snappiness at the cost of performance

lua/neotest-elixir/core.lua

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -132,27 +132,30 @@ function M.build_mix_command(
132132
neotest_args,
133133
relative_to_func
134134
)
135-
return vim.tbl_flatten({
136-
{
137-
"elixir",
138-
},
139-
-- deferent tasks have different options
140-
-- for example, `test.interactive` needs to load a custom runner
141-
options_for_task(mix_task_func()),
142-
{
143-
"-S",
144-
"mix",
145-
mix_task_func(), -- `test` is default
146-
},
147-
-- default is ExUnit.CLIFormatter
148-
build_formatters(extra_formatters_func()),
149-
-- default is {}
150-
-- maybe `test.interactive` has different args with `test`
151-
mix_task_args_func(),
152-
neotest_args.extra_args or {},
153-
-- test file or directory or testfile:line
154-
test_target(position, relative_to_func),
155-
})
135+
return vim
136+
.iter({
137+
{
138+
"elixir",
139+
},
140+
-- deferent tasks have different options
141+
-- for example, `test.interactive` needs to load a custom runner
142+
options_for_task(mix_task_func()),
143+
{
144+
"-S",
145+
"mix",
146+
mix_task_func(), -- `test` is default
147+
},
148+
-- default is ExUnit.CLIFormatter
149+
build_formatters(extra_formatters_func()),
150+
-- default is {}
151+
-- maybe `test.interactive` has different args with `test`
152+
mix_task_args_func(),
153+
neotest_args.extra_args or {},
154+
-- test file or directory or testfile:line
155+
test_target(position, relative_to_func),
156+
})
157+
:flatten()
158+
:totable()
156159
end
157160

158161
-- public only for testing

lua/neotest-elixir/init.lua

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@ function ElixirNeotestAdapter._generate_id(position, parents)
5454
return (relative_path .. ":" .. line_num)
5555
else
5656
return table.concat(
57-
vim.tbl_flatten({
58-
position.path,
59-
vim.tbl_map(function(pos)
60-
return pos.name
61-
end, parents),
62-
position.name,
63-
}),
57+
vim
58+
.iter({
59+
position.path,
60+
vim.tbl_map(function(pos)
61+
return pos.name
62+
end, parents),
63+
position.name,
64+
})
65+
:flatten()
66+
:totable(),
6467
"::"
6568
)
6669
end
@@ -178,7 +181,8 @@ end
178181
---@async
179182
---@return neotest.Tree | nil
180183
function ElixirNeotestAdapter.discover_positions(path)
181-
local test_block_id_list = vim.tbl_flatten({ { "test", "feature", "property" }, get_extra_block_identifiers() })
184+
local test_block_id_list =
185+
vim.iter({ { "test", "feature", "property" }, get_extra_block_identifiers() }):flatten():totable()
182186
for index, value in ipairs(test_block_id_list) do
183187
test_block_id_list[index] = '"' .. value .. '"'
184188
end

0 commit comments

Comments
 (0)