diff options
author | Steven Arcangeli <stevearc@stevearc.com> | 2023-09-29 16:47:00 -0700 |
---|---|---|
committer | Steven Arcangeli <stevearc@stevearc.com> | 2023-09-29 16:50:57 -0700 |
commit | 2cffcd332efdbfe19cb7e81b3fc326880b6a54cc (patch) | |
tree | ce3595bfae800ff0d93f4973aea1207a544f2600 | |
parent | d8170c14db0f3c90fa799db3bca29d3fb3c089c3 (diff) |
doc: speed up documentation generation
-rw-r--r-- | lua/conform/formatters/init.lua | 25 | ||||
-rwxr-xr-x | scripts/generate.py | 19 |
2 files changed, 34 insertions, 10 deletions
diff --git a/lua/conform/formatters/init.lua b/lua/conform/formatters/init.lua index b0e430e..c789e12 100644 --- a/lua/conform/formatters/init.lua +++ b/lua/conform/formatters/init.lua @@ -1,4 +1,29 @@ 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 diff --git a/scripts/generate.py b/scripts/generate.py index 6628c61..ae71c41 100755 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -33,21 +33,20 @@ class Formatter: name: str description: str url: str + deprecated: bool = False @lru_cache def get_all_formatters() -> List[Formatter]: - names = sorted( - [ - os.path.splitext(file)[0] - for file in os.listdir(os.path.join(ROOT, "lua", "conform", "formatters")) - ] - ) formatters = [] - for name in names: - meta = read_nvim_json(f'require("conform.formatters.{name}").meta') - if not meta.get("deprecated"): - formatters.append(Formatter(name, **meta)) + formatter_map = read_nvim_json( + 'require("conform.formatters").list_all_formatters()' + ) + for name, meta in formatter_map.items(): + formatter = Formatter(name, **meta) + if not formatter.deprecated: + formatters.append(formatter) + formatters.sort(key=lambda f: f.name) return formatters |