mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
fix(checkhealth): display error messages of failed queries
This commit is contained in:
parent
db1fa43484
commit
1375cc5c1f
3 changed files with 26 additions and 13 deletions
|
|
@ -43,10 +43,10 @@ local function install_health()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function query_status(lang, query_group)
|
local function query_status(lang, query_group)
|
||||||
local ok, found_query = pcall(queries.get_query, lang, query_group)
|
local ok, err = pcall(queries.get_query, lang, query_group)
|
||||||
if not ok then
|
if not ok then
|
||||||
return "x"
|
return "x", err
|
||||||
elseif not found_query then
|
elseif not err then
|
||||||
return "."
|
return "."
|
||||||
else
|
else
|
||||||
return "✓"
|
return "✓"
|
||||||
|
|
@ -54,8 +54,10 @@ local function query_status(lang, query_group)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.checkhealth()
|
function M.checkhealth()
|
||||||
|
local error_collection = {}
|
||||||
-- Installation dependency checks
|
-- Installation dependency checks
|
||||||
install_health()
|
install_health()
|
||||||
|
queries.invalidate_query_cache()
|
||||||
health_start("Parser/Features H L F I")
|
health_start("Parser/Features H L F I")
|
||||||
-- Parser installation checks
|
-- Parser installation checks
|
||||||
for _, parser_name in pairs(info.installed_parsers()) do
|
for _, parser_name in pairs(info.installed_parsers()) do
|
||||||
|
|
@ -66,7 +68,11 @@ function M.checkhealth()
|
||||||
local multiple_parsers = installed > 1 and "+" or ""
|
local multiple_parsers = installed > 1 and "+" or ""
|
||||||
local out = " - "..parser_name..multiple_parsers..string.rep(" ", 15 - (#parser_name + #multiple_parsers))
|
local out = " - "..parser_name..multiple_parsers..string.rep(" ", 15 - (#parser_name + #multiple_parsers))
|
||||||
for _, query_group in pairs(queries.built_in_query_groups) do
|
for _, query_group in pairs(queries.built_in_query_groups) do
|
||||||
out = out..query_status(parser_name, query_group).." "
|
local status, err = query_status(parser_name, query_group)
|
||||||
|
out = out..status.." "
|
||||||
|
if err then
|
||||||
|
table.insert(error_collection, {parser_name, query_group, err})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
print(out)
|
print(out)
|
||||||
end
|
end
|
||||||
|
|
@ -76,6 +82,13 @@ function M.checkhealth()
|
||||||
Legend: H[ighlight], L[ocals], F[olds], I[ndents]
|
Legend: H[ighlight], L[ocals], F[olds], I[ndents]
|
||||||
+) multiple parsers found, only one will be used
|
+) multiple parsers found, only one will be used
|
||||||
x) errors found in the query, try to run :TSUpdate {lang}]])
|
x) errors found in the query, try to run :TSUpdate {lang}]])
|
||||||
|
if #error_collection > 0 then
|
||||||
|
print('\nThe following errors have been detected:')
|
||||||
|
for _, p in ipairs(error_collection) do
|
||||||
|
local lang, type, err = unpack(p)
|
||||||
|
health_error(lang..'('..type..'): '..err)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -66,27 +66,27 @@ do
|
||||||
--- Same as `vim.treesitter.query` except will return cached values
|
--- Same as `vim.treesitter.query` except will return cached values
|
||||||
function M.get_query(lang, query_name)
|
function M.get_query(lang, query_name)
|
||||||
if cache[lang][query_name] == nil then
|
if cache[lang][query_name] == nil then
|
||||||
M.reload_file_cache(lang, query_name)
|
cache[lang][query_name] = tsq.get_query(lang, query_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
return cache[lang][query_name]
|
return cache[lang][query_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Reloads the query file cache.
|
--- Invalidates the query file cache.
|
||||||
--- If lang and query_name is both present, will reload for only the lang and query_name.
|
--- If lang and query_name is both present, will reload for only the lang and query_name.
|
||||||
--- If only lang is present, will reload all query_names for that lang
|
--- If only lang is present, will reload all query_names for that lang
|
||||||
--- If none are present, will reload everything
|
--- If none are present, will reload everything
|
||||||
function M.reload_file_cache(lang, query_name)
|
function M.invalidate_query_cache(lang, query_name)
|
||||||
if lang and query_name then
|
if lang and query_name then
|
||||||
cache[lang][query_name] = tsq.get_query(lang, query_name)
|
cache[lang][query_name] = nil
|
||||||
elseif lang and not query_name then
|
elseif lang and not query_name then
|
||||||
for query_name, _ in pairs(cache[lang]) do
|
for query_name, _ in pairs(cache[lang]) do
|
||||||
M.reload_file_cache(lang, query_name)
|
M.invalidate_query_cache(lang, query_name)
|
||||||
end
|
end
|
||||||
elseif not lang and not query_name then
|
elseif not lang and not query_name then
|
||||||
for lang, _ in pairs(cache) do
|
for lang, _ in pairs(cache) do
|
||||||
for query_name, _ in pairs(cache[lang]) do
|
for query_name, _ in pairs(cache[lang]) do
|
||||||
M.reload_file_cache(lang, query_name)
|
M.invalidate_query_cache(lang, query_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
@ -96,9 +96,9 @@ do
|
||||||
end
|
end
|
||||||
|
|
||||||
--- This function is meant for an autocommand and not to be used. Only use if file is a query file.
|
--- This function is meant for an autocommand and not to be used. Only use if file is a query file.
|
||||||
function M.reload_file_cache_on_write(fname)
|
function M.invalidate_query_file(fname)
|
||||||
local fnamemodify = vim.fn.fnamemodify
|
local fnamemodify = vim.fn.fnamemodify
|
||||||
M.reload_file_cache(fnamemodify(fname, ':p:h:t'), fnamemodify(fname, ':t:r'))
|
M.invalidate_query_cache(fnamemodify(fname, ':p:h:t'), fnamemodify(fname, ':t:r'))
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.iter_prepared_matches(query, qnode, bufnr, start_row, end_row)
|
function M.iter_prepared_matches(query, qnode, bufnr, start_row, end_row)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ endif
|
||||||
augroup NvimTreesitter
|
augroup NvimTreesitter
|
||||||
" on every query file write we want to set an autocommand that will reload the cache
|
" on every query file write we want to set an autocommand that will reload the cache
|
||||||
autocmd FileType query
|
autocmd FileType query
|
||||||
\ autocmd! NvimTreesitter BufWritePost <buffer> call v:lua.require('nvim-treesitter.query').reload_file_cache_on_write(expand('%:p'))
|
\ autocmd! NvimTreesitter BufWritePost <buffer> call v:lua.require('nvim-treesitter.query').invalidate_query_file(expand('%:p'))
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
let g:loaded_nvim_treesitter = 1
|
let g:loaded_nvim_treesitter = 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue