mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
refactor: use vim.uv
This commit is contained in:
parent
cd2c826972
commit
37957d6bcf
9 changed files with 40 additions and 62 deletions
1
.github/workflows/test-queries.yml
vendored
1
.github/workflows/test-queries.yml
vendored
|
|
@ -52,7 +52,6 @@ jobs:
|
||||||
env:
|
env:
|
||||||
CC: ${{ matrix.cc }}
|
CC: ${{ matrix.cc }}
|
||||||
NVIM: ${{ matrix.os == 'windows-latest' && 'nvim-win64\\bin\\nvim.exe' || 'nvim' }}
|
NVIM: ${{ matrix.os == 'windows-latest' && 'nvim-win64\\bin\\nvim.exe' || 'nvim' }}
|
||||||
ALLOWED_INSTALLATION_FAILURES: ${{ matrix.os == 'windows-latest' && 'rnoweb' }}
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: tree-sitter/setup-action/cli@v1
|
- uses: tree-sitter/setup-action/cli@v1
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ end
|
||||||
function M.get_install_dir(dir_name)
|
function M.get_install_dir(dir_name)
|
||||||
local dir = vim.fs.joinpath(config.install_dir, dir_name)
|
local dir = vim.fs.joinpath(config.install_dir, dir_name)
|
||||||
|
|
||||||
if not vim.loop.fs_stat(dir) then
|
if not vim.uv.fs_stat(dir) then
|
||||||
local ok, err = pcall(vim.fn.mkdir, dir, 'p', '0755')
|
local ok, err = pcall(vim.fn.mkdir, dir, 'p', '0755')
|
||||||
if not ok then
|
if not ok then
|
||||||
local log = require('nvim-treesitter.log')
|
local log = require('nvim-treesitter.log')
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ local function install_health()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.health.start('OS Info:\n' .. vim.inspect(vim.loop.os_uname()))
|
vim.health.start('OS Info:\n' .. vim.inspect(vim.uv.os_uname()))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function query_status(lang, query_group)
|
local function query_status(lang, query_group)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
local fs = vim.fs
|
local fs = vim.fs
|
||||||
local uv = vim.loop
|
local uv = vim.uv
|
||||||
|
|
||||||
local a = require('nvim-treesitter.async')
|
local a = require('nvim-treesitter.async')
|
||||||
local config = require('nvim-treesitter.config')
|
local config = require('nvim-treesitter.config')
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
-- Interface with Neovim job control and provide a simple job sequencing structure
|
-- Interface with Neovim job control and provide a simple job sequencing structure
|
||||||
local uv = vim.loop
|
local uv = vim.uv
|
||||||
local a = require('nvim-treesitter.async')
|
local a = require('nvim-treesitter.async')
|
||||||
local log = require('nvim-treesitter.log')
|
local log = require('nvim-treesitter.log')
|
||||||
|
|
||||||
|
|
@ -18,8 +18,8 @@ local M = { JobResult = {}, Opts = {} }
|
||||||
--- @field on_stderr fun(_: string)
|
--- @field on_stderr fun(_: string)
|
||||||
--- @field on_stdout fun(_: string)
|
--- @field on_stdout fun(_: string)
|
||||||
|
|
||||||
--- Wrapper for vim.loop.spawn. Takes a command, options, and callback just like
|
--- Wrapper for vim.uv.spawn. Takes a command, options, and callback just like
|
||||||
--- vim.loop.spawn, but ensures that all output from the command has been
|
--- vim.uv.spawn, but ensures that all output from the command has been
|
||||||
--- flushed before calling the callback.
|
--- flushed before calling the callback.
|
||||||
--- @param cmd string
|
--- @param cmd string
|
||||||
--- @param options uv.aliases.spawn_options
|
--- @param options uv.aliases.spawn_options
|
||||||
|
|
@ -66,7 +66,7 @@ end
|
||||||
|
|
||||||
--- Main exposed function for the jobs module. Takes a task and options and
|
--- Main exposed function for the jobs module. Takes a task and options and
|
||||||
--- returns an async function that will run the task with the given opts via
|
--- returns an async function that will run the task with the given opts via
|
||||||
--- vim.loop.spawn
|
--- vim.uv.spawn
|
||||||
--- @param task string[]
|
--- @param task string[]
|
||||||
--- @param opts JobOpts
|
--- @param opts JobOpts
|
||||||
--- @param callback fun(_: JobResult)
|
--- @param callback fun(_: JobResult)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
local uv = vim.loop
|
local uv = vim.uv
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,2 @@
|
||||||
((comment) @injection.content
|
((comment) @injection.content
|
||||||
(#set! injection.language "comment"))
|
(#set! injection.language "comment"))
|
||||||
|
|
||||||
((block_comment) @injection.content
|
|
||||||
(#set! injection.language "comment"))
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ local function do_check()
|
||||||
local timings = {}
|
local timings = {}
|
||||||
local parsers = require('nvim-treesitter.config').installed_parsers()
|
local parsers = require('nvim-treesitter.config').installed_parsers()
|
||||||
local query_types = require('nvim-treesitter.health').bundled_queries
|
local query_types = require('nvim-treesitter.health').bundled_queries
|
||||||
|
local configs = require('nvim-treesitter.parsers').configs
|
||||||
|
|
||||||
local captures = extract_captures()
|
local captures = extract_captures()
|
||||||
local errors = {}
|
local errors = {}
|
||||||
|
|
@ -46,30 +47,32 @@ local function do_check()
|
||||||
io_print('::group::Check parsers')
|
io_print('::group::Check parsers')
|
||||||
|
|
||||||
for _, lang in pairs(parsers) do
|
for _, lang in pairs(parsers) do
|
||||||
timings[lang] = {}
|
if configs[lang].install_info then
|
||||||
for _, query_type in pairs(query_types) do
|
timings[lang] = {}
|
||||||
local before = vim.loop.hrtime()
|
for _, query_type in pairs(query_types) do
|
||||||
local ok, query = pcall(vim.treesitter.query.get, lang, query_type)
|
local before = vim.uv.hrtime()
|
||||||
local after = vim.loop.hrtime()
|
local ok, query = pcall(vim.treesitter.query.get, lang, query_type)
|
||||||
local duration = after - before
|
local after = vim.uv.hrtime()
|
||||||
table.insert(timings, { duration = duration, lang = lang, query_type = query_type })
|
local duration = after - before
|
||||||
io_print(
|
table.insert(timings, { duration = duration, lang = lang, query_type = query_type })
|
||||||
'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
|
if not ok then
|
||||||
errors[#errors + 1] = err_msg
|
local err_msg = lang .. ' (' .. query_type .. '): ' .. query
|
||||||
else
|
errors[#errors + 1] = err_msg
|
||||||
if query then
|
else
|
||||||
for _, capture in ipairs(query.captures) do
|
if query then
|
||||||
local is_valid = (
|
for _, capture in ipairs(query.captures) do
|
||||||
vim.startswith(capture, '_') -- Helpers.
|
local is_valid = (
|
||||||
or vim.list_contains(captures[query_type], capture)
|
vim.startswith(capture, '_') -- Helpers.
|
||||||
)
|
or vim.list_contains(captures[query_type], capture)
|
||||||
if not is_valid then
|
)
|
||||||
local error =
|
if not is_valid then
|
||||||
string.format('(x) Invalid capture @%s in %s for %s.', capture, query_type, lang)
|
local error =
|
||||||
errors[#errors + 1] = error
|
string.format('(x) Invalid capture @%s in %s for %s.', capture, query_type, lang)
|
||||||
|
errors[#errors + 1] = error
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -90,27 +93,6 @@ local function do_check()
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok, result = pcall(do_check)
|
local ok, result = pcall(do_check)
|
||||||
local allowed_to_fail = vim.split(vim.env.ALLOWED_INSTALLATION_FAILURES or '', ',', true)
|
|
||||||
|
|
||||||
for k, v in pairs(require('nvim-treesitter.parsers').configs) do
|
|
||||||
if v.install_info then
|
|
||||||
-- skip "query only" languages
|
|
||||||
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.list_contains(allowed_to_fail, k)
|
|
||||||
then
|
|
||||||
io_print('Error: parser for ' .. k .. ' is not installed')
|
|
||||||
vim.cmd('cq')
|
|
||||||
else
|
|
||||||
io_print('Warning: parser for ' .. k .. ' is not installed')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if ok then
|
if ok then
|
||||||
io_print('::group::Timings')
|
io_print('::group::Timings')
|
||||||
table.sort(result, function(a, b)
|
table.sort(result, function(a, b)
|
||||||
|
|
|
||||||
|
|
@ -50,11 +50,11 @@ for _, v in ipairs(sorted_parsers) do
|
||||||
-- queries
|
-- queries
|
||||||
generated_text = generated_text
|
generated_text = generated_text
|
||||||
.. '`'
|
.. '`'
|
||||||
.. (vim.loop.fs_stat('runtime/queries/' .. v.name .. '/highlights.scm') and 'H' or ' ')
|
.. (vim.uv.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.uv.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.uv.fs_stat('runtime/queries/' .. v.name .. '/indents.scm') and 'I' or ' ')
|
||||||
.. (vim.loop.fs_stat('runtime/queries/' .. v.name .. '/injections.scm') and 'J' or ' ')
|
.. (vim.uv.fs_stat('runtime/queries/' .. v.name .. '/injections.scm') and 'J' or ' ')
|
||||||
.. (vim.loop.fs_stat('runtime/queries/' .. v.name .. '/locals.scm') and 'L' or ' ')
|
.. (vim.uv.fs_stat('runtime/queries/' .. v.name .. '/locals.scm') and 'L' or ' ')
|
||||||
.. '` | '
|
.. '` | '
|
||||||
|
|
||||||
-- CLI
|
-- CLI
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue