Skip to content

Commit 200c2ce

Browse files
committed
chore(mise): add task to clean unsupported parsers
1 parent 3107d79 commit 200c2ce

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

mise.toml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,72 @@ tree-sitter = "latest"
1818
[tasks.ruler] # command: mise run ruler
1919
description = "Compile ruler to AGENTS.md"
2020
run = "bunx @intellectronica/ruler apply"
21+
22+
[tasks.clean-unsupported-ts-parsers] # command: mise run clean-unsupported-ts-parsers
23+
description = "Remove installed nvim-treesitter parsers that are no longer supported"
24+
run = '''
25+
tmp_vim="${TMPDIR:-/tmp}/nvim-clean-unsupported-ts-parsers.vim"
26+
cat > "$tmp_vim" <<'EOF'
27+
lua << LUA
28+
local config = require("nvim-treesitter.config")
29+
30+
local available = {}
31+
for _, lang in ipairs(config.get_available()) do
32+
available[lang] = true
33+
end
34+
35+
local unsupported = {}
36+
for _, lang in ipairs(config.get_installed()) do
37+
if not available[lang] then
38+
table.insert(unsupported, lang)
39+
end
40+
end
41+
table.sort(unsupported)
42+
43+
if #unsupported == 0 then
44+
print("No unsupported nvim-treesitter parsers found")
45+
vim.cmd.quitall()
46+
return
47+
end
48+
49+
local parser_dir = config.get_install_dir("parser")
50+
local parser_info_dir = config.get_install_dir("parser-info")
51+
local query_dir = config.get_install_dir("queries")
52+
53+
for _, lang in ipairs(unsupported) do
54+
local removed = {}
55+
56+
for _, parser in ipairs(vim.fn.globpath(parser_dir, lang .. ".*", false, true)) do
57+
if vim.fn.delete(parser) == 0 then
58+
table.insert(removed, parser)
59+
end
60+
end
61+
62+
local revision = vim.fs.joinpath(parser_info_dir, lang .. ".revision")
63+
if vim.fn.filereadable(revision) == 1 and vim.fn.delete(revision) == 0 then
64+
table.insert(removed, revision)
65+
end
66+
67+
local queries = vim.fs.joinpath(query_dir, lang)
68+
if vim.fn.isdirectory(queries) == 1 and vim.fn.delete(queries, "rf") == 0 then
69+
table.insert(removed, queries)
70+
end
71+
72+
if #removed == 0 then
73+
print(("No files removed for unsupported parser: %s"):format(lang))
74+
else
75+
print(("Removed unsupported parser: %s"):format(lang))
76+
for _, path in ipairs(removed) do
77+
print(" " .. path)
78+
end
79+
end
80+
end
81+
82+
vim.cmd.quitall()
83+
LUA
84+
EOF
85+
86+
export NVIM_LOG_FILE="${NVIM_LOG_FILE:-${TMPDIR:-/tmp}/nvim-clean-unsupported-ts-parsers.log}"
87+
nvim --headless -i NONE -S "$tmp_vim"
88+
rm -f "$tmp_vim"
89+
'''

0 commit comments

Comments
 (0)