nix-config/modules2/nixvim/edit-alternate/config.nix

60 lines
1.8 KiB
Nix
Raw Normal View History

2025-07-29 11:27:46 +01:00
{
flake.modules.nixvim.custom.extraConfigLua = ''
2025-07-30 00:14:05 +01:00
local add_rule = function(ft, fn)
vim.fn["edit_alternate#rule#add"](ft, fn)
end
add_rule("go", function(filename)
2025-07-30 00:00:27 +01:00
return filename:find "_test%.go$"
and filename:gsub("_test%.go$", ".go")
or filename:gsub("%.go$", "_test.go")
end)
2025-07-30 00:14:05 +01:00
add_rule("php", function(filename)
2025-07-29 11:27:46 +01:00
if filename:find "Test.php$" then
filename = filename:gsub("Test.php$", ".php")
2025-07-30 00:00:27 +01:00
return filename:find "tests/src/"
and filename:gsub("tests/src/(.-)/", "src/")
2025-07-30 00:14:05 +01:00
or filename:gsub("tests/", "src/")
2025-07-29 11:27:46 +01:00
else
2025-07-30 00:14:05 +01:00
local test_filename = filename:gsub("%.php$", "Test.php")
2025-07-29 11:27:46 +01:00
2025-07-30 00:00:27 +01:00
if test_filename:find "modules/custom" then
2025-07-29 11:27:46 +01:00
local test_types = { "Functional", "FunctionalJavaScript", "Kernel", "Unit" }
for _, test_type in ipairs(test_types) do
2025-07-30 00:00:27 +01:00
local candidate = test_filename:gsub("src/", string.format("tests/src/%s/", test_type))
2025-07-29 11:27:46 +01:00
2025-07-30 00:00:27 +01:00
if vim.fn.filereadable(candidate) == 1 then
return candidate
2025-07-29 11:27:46 +01:00
end
end
end
2025-07-30 00:00:27 +01:00
return test_filename
2025-07-29 11:27:46 +01:00
end
end)
if vim.fn.filereadable "composer.json" == 1 then
2025-07-30 00:14:05 +01:00
add_rule("json", function(filename)
return filename:find "composer.json" and filename:gsub("%.json$", ".lock") or nil
2025-07-29 11:27:46 +01:00
end)
2025-07-30 00:14:05 +01:00
add_rule("lock", function(filename)
return filename:find "composer.lock" and filename:gsub("%.lock$", ".json") or nil
2025-07-29 11:27:46 +01:00
end)
end
if vim.fn.filereadable "fractal.config.js" == 1 then
2025-07-30 00:14:05 +01:00
add_rule("twig", function(filename)
2025-07-30 00:00:27 +01:00
return filename:gsub("%.twig$", ".config.yml")
2025-07-29 11:27:46 +01:00
end)
2025-07-30 00:14:05 +01:00
add_rule("yml", function(filename)
2025-07-30 00:00:27 +01:00
return filename:gsub("%.config.yml$", ".twig")
2025-07-29 11:27:46 +01:00
end)
end
'';
}