mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
Use stylua for autoformat code (#1480)
This commit is contained in:
parent
90f15d9bf7
commit
be8f656087
32 changed files with 1181 additions and 979 deletions
|
|
@ -1,7 +1,7 @@
|
|||
-- Execute as `nvim --headless -c "luafile ./scripts/check-queries.lua"`
|
||||
|
||||
local function extract_captures()
|
||||
local lines = vim.fn.readfile("CONTRIBUTING.md")
|
||||
local lines = vim.fn.readfile "CONTRIBUTING.md"
|
||||
local captures = {}
|
||||
local current_query
|
||||
|
||||
|
|
@ -18,17 +18,17 @@ local function extract_captures()
|
|||
end
|
||||
|
||||
-- Complete captures for injections.
|
||||
local parsers = require 'nvim-treesitter.info'.installed_parsers()
|
||||
local parsers = require("nvim-treesitter.info").installed_parsers()
|
||||
for _, lang in pairs(parsers) do
|
||||
table.insert(captures['injections'], lang)
|
||||
table.insert(captures["injections"], lang)
|
||||
end
|
||||
|
||||
return captures
|
||||
end
|
||||
|
||||
local function do_check()
|
||||
local parsers = require 'nvim-treesitter.info'.installed_parsers()
|
||||
local queries = require 'nvim-treesitter.query'
|
||||
local parsers = require("nvim-treesitter.info").installed_parsers()
|
||||
local queries = require "nvim-treesitter.query"
|
||||
local query_types = queries.built_in_query_groups
|
||||
|
||||
local captures = extract_captures()
|
||||
|
|
@ -36,7 +36,7 @@ local function do_check()
|
|||
|
||||
for _, lang in pairs(parsers) do
|
||||
for _, query_type in pairs(query_types) do
|
||||
print('Checking '..lang..' '..query_type)
|
||||
print("Checking " .. lang .. " " .. query_type)
|
||||
local ok, query = pcall(queries.get_query, lang, query_type)
|
||||
if not ok then
|
||||
vim.api.nvim_err_writeln(query)
|
||||
|
|
@ -45,9 +45,9 @@ local function do_check()
|
|||
if query then
|
||||
for _, capture in ipairs(query.captures) do
|
||||
local is_valid = (
|
||||
vim.startswith(capture, "_") -- Helpers.
|
||||
or vim.tbl_contains(captures[query_type], capture)
|
||||
)
|
||||
vim.startswith(capture, "_") -- Helpers.
|
||||
or vim.tbl_contains(captures[query_type], capture)
|
||||
)
|
||||
if not is_valid then
|
||||
local error = string.format("(x) Invalid capture @%s in %s for %s.", capture, query_type, lang)
|
||||
print(error)
|
||||
|
|
@ -60,36 +60,36 @@ local function do_check()
|
|||
end
|
||||
if last_error then
|
||||
print()
|
||||
print("Last error: ")
|
||||
print "Last error: "
|
||||
error(last_error)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local ok, err = 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").get_parser_configs()) do
|
||||
if not require("nvim-treesitter.parsers").has_parser(k) then
|
||||
-- On CI all parsers that can be installed from C files should be installed
|
||||
if vim.env.CI
|
||||
if
|
||||
vim.env.CI
|
||||
and not v.install_info.requires_generate_from_grammar
|
||||
and not vim.tbl_contains(allowed_to_fail, k) then
|
||||
|
||||
print('Error: parser for '..k..' is not installed')
|
||||
vim.cmd('cq')
|
||||
and not vim.tbl_contains(allowed_to_fail, k)
|
||||
then
|
||||
print("Error: parser for " .. k .. " is not installed")
|
||||
vim.cmd "cq"
|
||||
else
|
||||
print('Warning: parser for '..k..' is not installed')
|
||||
print("Warning: parser for " .. k .. " is not installed")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if ok then
|
||||
print('Check successful!\n')
|
||||
vim.cmd('q')
|
||||
print "Check successful!\n"
|
||||
vim.cmd "q"
|
||||
else
|
||||
print('Check failed:')
|
||||
print "Check failed:"
|
||||
print(err)
|
||||
print('\n')
|
||||
vim.cmd('cq')
|
||||
print "\n"
|
||||
vim.cmd "cq"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ vim.cmd [[runtime! plugin/nvim-treesitter.vim]]
|
|||
vim.o.swapfile = false
|
||||
vim.bo.swapfile = false
|
||||
|
||||
require('nvim-treesitter.configs').setup {
|
||||
ensure_installed = 'maintained',
|
||||
indent = { enable = true },
|
||||
require("nvim-treesitter.configs").setup {
|
||||
ensure_installed = "maintained",
|
||||
indent = { enable = true },
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,41 +1,49 @@
|
|||
-- Execute as `nvim --headless -c "luafile ./scripts/update-readme.lua"`
|
||||
local parsers = require 'nvim-treesitter.parsers'.get_parser_configs()
|
||||
local parsers = require("nvim-treesitter.parsers").get_parser_configs()
|
||||
local sorted_parsers = {}
|
||||
|
||||
for k, v in pairs(parsers) do
|
||||
table.insert(sorted_parsers, {name = k, parser = v})
|
||||
table.insert(sorted_parsers, { name = k, parser = v })
|
||||
end
|
||||
|
||||
table.sort(sorted_parsers, function(a, b) return a.name < b.name end)
|
||||
table.sort(sorted_parsers, function(a, b)
|
||||
return a.name < b.name
|
||||
end)
|
||||
|
||||
local generated_text = ''
|
||||
local generated_text = ""
|
||||
|
||||
for _, v in ipairs(sorted_parsers) do
|
||||
local link = '['..(v.parser.readme_name or v.name)..']('..v.parser.install_info.url..')'
|
||||
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..' (maintained by '..table.concat(v.parser.maintainers, ', ')..')\n'
|
||||
generated_text = generated_text
|
||||
.. "- [x] "
|
||||
.. link
|
||||
.. " (maintained by "
|
||||
.. table.concat(v.parser.maintainers, ", ")
|
||||
.. ")\n"
|
||||
else
|
||||
generated_text = generated_text..
|
||||
'- [ ] '..link..'\n'
|
||||
generated_text = generated_text .. "- [ ] " .. link .. "\n"
|
||||
end
|
||||
end
|
||||
|
||||
print(generated_text)
|
||||
print("\n")
|
||||
print "\n"
|
||||
|
||||
local readme_text = table.concat(vim.fn.readfile('README.md'), '\n')
|
||||
local readme_text = table.concat(vim.fn.readfile "README.md", "\n")
|
||||
|
||||
local new_readme_text = string.gsub(readme_text, "<!%-%-parserinfo%-%->.*<!%-%-parserinfo%-%->",
|
||||
"<!--parserinfo-->\n"..generated_text.."<!--parserinfo-->")
|
||||
vim.fn.writefile(vim.fn.split(new_readme_text, '\n'), "README.md")
|
||||
local new_readme_text = string.gsub(
|
||||
readme_text,
|
||||
"<!%-%-parserinfo%-%->.*<!%-%-parserinfo%-%->",
|
||||
"<!--parserinfo-->\n" .. generated_text .. "<!--parserinfo-->"
|
||||
)
|
||||
vim.fn.writefile(vim.fn.split(new_readme_text, "\n"), "README.md")
|
||||
|
||||
if string.find(readme_text, generated_text, 1, 'plain') then
|
||||
print("README.md is up-to-date!")
|
||||
vim.cmd('q')
|
||||
if string.find(readme_text, generated_text, 1, "plain") then
|
||||
print "README.md is up-to-date!"
|
||||
vim.cmd "q"
|
||||
else
|
||||
print("New README.md was written. Please commit that change! Old text was: ")
|
||||
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')
|
||||
vim.cmd "cq"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
-- Execute as `nvim --headless -c "luafile ./scripts/write-lockfile.lua"`
|
||||
local skip_langs = vim.fn.getenv('SKIP_LOCKFILE_UPDATE_FOR_LANGS')
|
||||
local skip_langs = vim.fn.getenv "SKIP_LOCKFILE_UPDATE_FOR_LANGS"
|
||||
if skip_langs == vim.NIL then
|
||||
skip_langs = {}
|
||||
else
|
||||
skip_langs = vim.fn.split(skip_langs, ',')
|
||||
skip_langs = vim.fn.split(skip_langs, ",")
|
||||
end
|
||||
print("Skipping languages: "..vim.inspect(skip_langs))
|
||||
require 'nvim-treesitter.install'.write_lockfile('verbose', skip_langs)
|
||||
vim.cmd('q')
|
||||
print("Skipping languages: " .. vim.inspect(skip_langs))
|
||||
require("nvim-treesitter.install").write_lockfile("verbose", skip_langs)
|
||||
vim.cmd "q"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue