feat!: drop modules, general refactor and cleanup

This commit is contained in:
Christian Clason 2023-06-12 09:54:30 -06:00
parent c13e28f894
commit 2c8f2f2fad
829 changed files with 4905 additions and 8010 deletions

View file

@ -1,35 +1,35 @@
#!/usr/bin/env -S nvim -l
vim.opt.runtimepath:append('.')
-- Equivalent to print(), but this will ensure consistent output regardless of
-- operating system.
local function io_print(text)
if not text then
text = ""
text = ''
end
io.write(text, "\n")
io.write(text, '\n')
end
local function extract_captures()
local lines = vim.fn.readfile "CONTRIBUTING.md"
local captures = {}
local current_query
for _, line in ipairs(lines) do
if vim.startswith(line, "### ") then
current_query = vim.fn.tolower(line:sub(5))
elseif vim.startswith(line, "@") and current_query then
for line in io.lines('CONTRIBUTING.md') do
if vim.startswith(line, '### ') then
current_query = line:sub(5):lower()
elseif vim.startswith(line, '@') and current_query then
if not captures[current_query] then
captures[current_query] = {}
end
table.insert(captures[current_query], vim.split(line:sub(2), " ", true)[1])
table.insert(captures[current_query], vim.split(line:sub(2), ' ', true)[1])
end
end
-- Complete captures for injections.
local parsers = vim.tbl_keys(require("nvim-treesitter.parsers").list)
local parsers = vim.tbl_keys(require('nvim-treesitter.parsers').configs)
for _, lang in pairs(parsers) do
table.insert(captures["injections"], lang)
table.insert(captures['injections'], lang)
end
return captures
@ -46,39 +46,41 @@ end
local function do_check()
local timings = {}
local parsers = require("nvim-treesitter.info").installed_parsers()
local queries = require "nvim-treesitter.query"
local query_types = queries.built_in_query_groups
local parsers = require('nvim-treesitter.config').installed_parsers()
local query_types = require('nvim-treesitter.health').bundled_queries
local captures = extract_captures()
local last_error
io_print "::group::Check parsers"
io_print('::group::Check parsers')
for _, lang in pairs(parsers) do
timings[lang] = {}
for _, query_type in pairs(query_types) do
local before = vim.loop.hrtime()
local ok, query = pcall(queries.get_query, lang, query_type)
local ok, query = pcall(vim.treesitter.query.get, lang, query_type)
local after = vim.loop.hrtime()
local duration = after - before
table.insert(timings, { duration = duration, lang = lang, query_type = query_type })
io_print("Checking " .. lang .. " " .. query_type .. string.format(" (%.02fms)", duration * 1e-6))
io_print(
'Checking ' .. lang .. ' ' .. query_type .. string.format(' (%.02fms)', duration * 1e-6)
)
if not ok then
local err_msg = lang .. " (" .. query_type .. "): " .. query
local err_msg = lang .. ' (' .. query_type .. '): ' .. query
io_print(err_msg)
last_error = err_msg
else
if query then
for _, capture in ipairs(query.captures) do
local is_valid = (
vim.startswith(capture, "_") -- Helpers.
vim.startswith(capture, '_') -- Helpers.
or list_any(captures[query_type], function(documented_capture)
return vim.startswith(capture, documented_capture)
end)
)
if not is_valid then
local error = string.format("(x) Invalid capture @%s in %s for %s.", capture, query_type, lang)
local error =
string.format('(x) Invalid capture @%s in %s for %s.', capture, query_type, lang)
io_print(error)
last_error = error
end
@ -88,49 +90,55 @@ local function do_check()
end
end
io_print "::endgroup::"
io_print('::endgroup::')
if last_error then
io_print()
io_print "Last error: "
io_print('Last error: ')
error(last_error)
end
return timings
end
local ok, result = pcall(do_check)
local allowed_to_fail = vim.split(vim.env.ALLOWED_INSTALLATION_FAILURES or "", ",", true)
local allowed_to_fail = vim.split(vim.env.ALLOWED_INSTALLATION_FAILURES or '', ',', true)
for k, v in pairs(require("nvim-treesitter.parsers").get_parser_configs()) do
if not require("nvim-treesitter.parsers").has_parser(k) then
for k, v in pairs(require('nvim-treesitter.parsers').configs) do
if #vim.api.nvim_get_runtime_file('parser/' .. k .. '.*', false) == 0 then
-- On CI all parsers that can be installed from C files should be installed
if
vim.env.CI
and not v.install_info.requires_generate_from_grammar
and not vim.tbl_contains(allowed_to_fail, k)
and not vim.list_contains(allowed_to_fail, k)
then
io_print("Error: parser for " .. k .. " is not installed")
vim.cmd "cq"
io_print('Error: parser for ' .. k .. ' is not installed')
vim.cmd('cq')
else
io_print("Warning: parser for " .. k .. " is not installed")
io_print('Warning: parser for ' .. k .. ' is not installed')
end
end
end
if ok then
io_print "::group::Timings"
io_print('::group::Timings')
table.sort(result, function(a, b)
return a.duration < b.duration
end)
for i, val in ipairs(result) do
io_print(string.format("%i. %.02fms %s %s", #result - i + 1, val.duration * 1e-6, val.lang, val.query_type))
io_print(
string.format(
'%i. %.02fms %s %s',
#result - i + 1,
val.duration * 1e-6,
val.lang,
val.query_type
)
)
end
io_print "::endgroup::"
io_print "Check successful!"
vim.cmd "q"
io_print('::endgroup::')
io_print('Check successful!')
else
io_print "Check failed:"
io_print('Check failed:')
io_print(result)
io_print "\n"
vim.cmd "cq"
io_print('\n')
end

View file

@ -1,25 +1,29 @@
vim.opt.runtimepath:append "."
vim.cmd.runtime { "plugin/plenary.vim", bang = true }
vim.cmd.runtime { "plugin/nvim-treesitter.lua", bang = true }
vim.opt.runtimepath:append('.')
vim.cmd.runtime({ 'plugin/plenary.vim', bang = true })
vim.cmd.runtime({ 'plugin/nvim-treesitter.lua', bang = true })
vim.cmd.runtime({ 'plugin/query_predicates.lua', bang = true })
vim.filetype.add {
vim.filetype.add({
extension = {
conf = "hocon",
cmm = "t32",
hurl = "hurl",
ncl = "nickel",
tig = "tiger",
usd = "usd",
usda = "usd",
wgsl = "wgsl",
w = "wing",
conf = 'hocon',
cmm = 't32',
hurl = 'hurl',
ncl = 'nickel',
tig = 'tiger',
usd = 'usd',
usda = 'usd',
wgsl = 'wgsl',
w = 'wing',
},
}
})
vim.o.swapfile = false
vim.bo.swapfile = false
require("nvim-treesitter.configs").setup {
indent = { enable = true },
highlight = { enable = true },
}
require('nvim-treesitter').setup()
vim.api.nvim_create_autocmd('FileType', {
callback = function(args)
pcall(vim.treesitter.start)
vim.bo[args.buffer].indentexpr = 'v:lua.require"nvim-treesitter".indentexpr()'
end,
})

View file

@ -14,7 +14,7 @@ make_ignored() {
TO_IGNORE=$(make_ignored $1)
SKIP_LOCKFILE_UPDATE_FOR_LANGS="$TO_IGNORE" nvim --headless -c "luafile ./scripts/write-lockfile.lua" -c "q"
SKIP_LOCKFILE_UPDATE_FOR_LANGS="$TO_IGNORE" nvim -l ./scripts/write-lockfile.lua
# Pretty print
cp lockfile.json /tmp/lockfile.json
cat /tmp/lockfile.json | jq --sort-keys > lockfile.json

View file

@ -1,59 +1,85 @@
#!/usr/bin/env -S nvim -l
vim.opt.runtimepath:append('.')
---@class Parser
---@field name string
---@field parser ParserInfo
local parsers = require("nvim-treesitter.parsers").get_parser_configs()
local parsers = require('nvim-treesitter.parsers').configs
local sorted_parsers = {}
for k, v in pairs(parsers) do
table.insert(sorted_parsers, { name = k, parser = v })
end
---@param a Parser
---@param b Parser
table.sort(sorted_parsers, function(a, b)
return a.name < b.name
end)
local generated_text = ""
local tiers = require('nvim-treesitter.parsers').tiers
local generated_text = [[
Language | Tier | Queries | CLI | NPM | Maintainer
-------- |:----:|:-------:|:---:|:---:| ----------
]]
local footnotes = ''
---@param v Parser
for _, v in ipairs(sorted_parsers) do
local link = "[" .. (v.parser.readme_name or v.name) .. "](" .. v.parser.install_info.url .. ")"
if v.parser.maintainers then
generated_text = generated_text
.. "- [x] "
.. link
.. " ("
.. (v.parser.experimental and "experimental, " or "")
.. "maintained by "
.. table.concat(v.parser.maintainers, ", ")
.. ")\n"
else
generated_text = generated_text .. "- [ ] " .. link .. (v.parser.experimental and " (experimental)" or "") .. "\n"
local p = v.parser
-- language
generated_text = generated_text
.. '['
.. v.name
.. ']('
.. p.install_info.url
.. ')'
.. (p.readme_note and '[^' .. v.name .. ']' or '')
.. ' | '
if p.readme_note then
footnotes = footnotes .. '[^' .. v.name .. ']: ' .. p.readme_note .. '\n'
end
-- tier
generated_text = generated_text .. (p.tier and tiers[p.tier] or '') .. ' | '
-- queries
generated_text = generated_text
.. '`'
.. (vim.loop.fs_stat('runtime/queries/' .. v.name .. '/highlights.scm') and 'H' or ' ')
.. (vim.loop.fs_stat('runtime/queries/' .. v.name .. '/folds.scm') and 'F' or ' ')
.. (vim.loop.fs_stat('runtime/queries/' .. v.name .. '/indents.scm') and 'I' or ' ')
.. (vim.loop.fs_stat('runtime/queries/' .. v.name .. '/injections.scm') and 'J' or ' ')
.. '` | '
-- CLI
generated_text = generated_text
.. (p.install_info.requires_generate_from_grammar and '' or '')
.. ' | '
-- NPM
generated_text = generated_text .. (p.install_info.generate_requires_npm and '' or '') .. ' | '
-- Maintainer
generated_text = generated_text
.. (p.maintainers and table.concat(p.maintainers, ', ') or '')
.. '\n'
end
generated_text = generated_text .. footnotes
print(generated_text)
print "\n"
local readme_text = table.concat(vim.fn.readfile "README.md", "\n")
local readme = assert(io.open('SUPPORTED_LANGUAGES.md', 'r'))
local readme_text = readme:read('*a')
readme:close()
local new_readme_text = string.gsub(
readme_text,
"<!%-%-parserinfo%-%->.*<!%-%-parserinfo%-%->",
"<!--parserinfo-->\n" .. generated_text .. "<!--parserinfo-->"
'<!%-%-parserinfo%-%->.*<!%-%-parserinfo%-%->',
'<!--parserinfo-->\n' .. generated_text .. '<!--parserinfo-->'
)
vim.fn.writefile(vim.fn.split(new_readme_text, "\n"), "README.md")
readme = assert(io.open('SUPPORTED_LANGUAGES.md', 'w'))
readme:write(new_readme_text)
readme:close()
if string.find(readme_text, generated_text, 1, true) then
print "README.md is up-to-date!"
vim.cmd "q"
print('README.md is up-to-date\n')
else
print "New README.md was written. Please commit that change! Old text was: "
print(string.sub(readme_text, string.find(readme_text, "<!%-%-parserinfo%-%->.*<!%-%-parserinfo%-%->")))
vim.cmd "cq"
print('New README.md was written\n')
end

View file

@ -1,15 +1,52 @@
#!/usr/bin/env -S nvim -l
vim.opt.runtimepath:append('.')
---@type string|any[]
local skip_langs = vim.fn.getenv "SKIP_LOCKFILE_UPDATE_FOR_LANGS"
-- Load previous lockfile
local filename = require('nvim-treesitter.utils').get_package_path('lockfile.json')
local file = assert(io.open(filename, 'r'))
local lockfile = vim.json.decode(file:read('*a'))
file:close()
if skip_langs == vim.NIL then
skip_langs = {}
else
---@diagnostic disable-next-line: param-type-mismatch
skip_langs = vim.fn.split(skip_langs, ",")
---@type string?
local skip_lang_string = os.getenv('SKIP_LOCKFILE_UPDATE_FOR_LANGS')
local skip_langs = skip_lang_string and vim.split(skip_lang_string, ',') or {}
vim.print('Skipping languages: ', skip_langs)
local sorted_parsers = {}
local configs = require('nvim-treesitter.parsers').configs
for k, v in pairs(configs) do
table.insert(sorted_parsers, { name = k, parser = v })
end
table.sort(sorted_parsers, function(a, b)
return a.name < b.name
end)
print("Skipping languages: " .. vim.inspect(skip_langs))
require("nvim-treesitter.install").write_lockfile("verbose", skip_langs)
vim.cmd "q"
-- check for new revisions
for _, v in ipairs(sorted_parsers) do
if skip_langs and not vim.list_contains(skip_langs, v.name) then
local sha ---@type string
if v.parser.install_info.branch then
sha = vim.split(
vim.fn.systemlist(
'git ls-remote '
.. v.parser.install_info.url
.. ' | grep refs/heads/'
.. v.parser.install_info.branch
)[1],
'\t'
)[1]
else
sha = vim.split(vim.fn.systemlist('git ls-remote ' .. v.parser.install_info.url)[1], '\t')[1]
end
lockfile[v.name] = { revision = sha }
print(v.name .. ': ' .. sha)
else
print('Skipping ' .. v.name)
end
end
vim.print(lockfile)
-- write new lockfile
file = assert(io.open(filename, 'w'))
file:write(vim.json.encode(lockfile))
file:close()