blob: c789e129da17450fcddf5add677f3b54216fda87 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
local M = {}
local uv = vim.uv or vim.loop
-- This is used for documentation generation
M.list_all_formatters = function()
local ret = {}
for path in vim.gsplit(vim.o.runtimepath, ",", { plain = true }) do
local formatter_path = path .. "/lua/conform/formatters"
local formatter_dir = uv.fs_opendir(formatter_path)
if formatter_dir then
local entries = uv.fs_readdir(formatter_dir)
while entries do
for _, entry in ipairs(entries) do
if entry.name ~= "init.lua" then
local basename = string.match(entry.name, "^(.*)%.lua$")
local module = require("conform.formatters." .. basename)
ret[basename] = module.meta
end
end
entries = uv.fs_readdir(formatter_dir)
end
uv.fs_closedir(formatter_dir)
end
end
return ret
end
-- A little metatable magic to allow accessing formatters like
-- require("conform.formatters").prettier
return setmetatable(M, {
__index = function(_, k)
return require("conform.formatters." .. k)
end,
})
|