mirror of
https://github.com/nix-community/nixvim.git
synced 2026-08-24 02:34:15 -05:00
plugins/treesitter: return early if there is no parser available
This commit is contained in:
committed by
Matt Sturgeon
parent
dc0c5e350e
commit
b79ccde69a
@@ -373,6 +373,9 @@ lib.nixvim.plugins.mkNeovimPlugin {
|
||||
return
|
||||
end
|
||||
local has_parser = vim.treesitter.language.add(lang)
|
||||
if not has_parser then
|
||||
return
|
||||
end
|
||||
|
||||
local function has_query(query_name)
|
||||
return vim.treesitter.query.get(lang, query_name) ~= nil
|
||||
@@ -398,7 +401,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
|
||||
|
||||
${optionalString highlightEnabled ''
|
||||
local disabled_highlight = ${lib.nixvim.toLuaObject cfg.highlight.disable}
|
||||
if has_parser and has_query('highlights') and not is_disabled(disabled_highlight) then
|
||||
if has_query('highlights') and not is_disabled(disabled_highlight) then
|
||||
vim.treesitter.start(buf, lang)
|
||||
add_undo_ftplugin(("call v:lua.vim.treesitter.stop(%d)"):format(buf))
|
||||
|
||||
@@ -409,13 +412,13 @@ lib.nixvim.plugins.mkNeovimPlugin {
|
||||
end
|
||||
''}${optionalString indentEnabled ''
|
||||
local disabled_indent = ${lib.nixvim.toLuaObject cfg.indent.disable}
|
||||
if has_parser and has_query('indents') and not is_disabled(disabled_indent) then
|
||||
if has_query('indents') and not is_disabled(disabled_indent) then
|
||||
vim.bo[buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||
add_undo_ftplugin('setlocal indentexpr<')
|
||||
end
|
||||
''}${optionalString cfg.folding.enable ''
|
||||
local disabled_folding = ${lib.nixvim.toLuaObject cfg.folding.disable}
|
||||
if has_parser and has_query('folds') and not is_disabled(disabled_folding) then
|
||||
if has_query('folds') and not is_disabled(disabled_folding) then
|
||||
vim.wo[0][0].foldexpr = 'v:lua.vim.treesitter.foldexpr()'
|
||||
vim.wo[0][0].foldmethod = 'expr'
|
||||
add_undo_ftplugin('setlocal foldexpr< foldmethod<')
|
||||
|
||||
@@ -53,8 +53,8 @@
|
||||
message = "Treesitter highlight disable check should match language and filetype.";
|
||||
}
|
||||
{
|
||||
assertion = lib.hasInfix "if has_parser and has_query('highlights') and not is_disabled(disabled_highlight) then" config.content;
|
||||
message = "Treesitter highlight should be enabled only if there are parser and queries, and if not disabled.";
|
||||
assertion = lib.hasInfix "if has_query('highlights') and not is_disabled(disabled_highlight) then" config.content;
|
||||
message = "Treesitter highlight should be enabled only if there are queries, and if not disabled.";
|
||||
}
|
||||
{
|
||||
assertion = lib.hasInfix "vim.treesitter.start(buf, lang)" config.content;
|
||||
@@ -100,8 +100,8 @@
|
||||
message = "Treesitter indentation disable list should be present in generated lua.";
|
||||
}
|
||||
{
|
||||
assertion = lib.hasInfix "if has_parser and has_query('indents') and not is_disabled(disabled_indent) then" config.content;
|
||||
message = "Treesitter indentation should be enabled only if there are parser and queries, and if not disabled.";
|
||||
assertion = lib.hasInfix "if has_query('indents') and not is_disabled(disabled_indent) then" config.content;
|
||||
message = "Treesitter indentation should be enabled only if there are queries, and if not disabled.";
|
||||
}
|
||||
{
|
||||
assertion = lib.hasInfix ''vim.bo[buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"'' config.content;
|
||||
@@ -134,8 +134,8 @@
|
||||
message = "Treesitter folding disable list should be present in generated lua.";
|
||||
}
|
||||
{
|
||||
assertion = lib.hasInfix "if has_parser and has_query('folds') and not is_disabled(disabled_folding) then" config.content;
|
||||
message = "Treesitter folding should be enabled only if there are parser and queries, and if not disabled.";
|
||||
assertion = lib.hasInfix "if has_query('folds') and not is_disabled(disabled_folding) then" config.content;
|
||||
message = "Treesitter folding should be enabled only if there are queries, and if not disabled.";
|
||||
}
|
||||
{
|
||||
assertion = lib.hasInfix "vim.wo[0][0].foldexpr = 'v:lua.vim.treesitter.foldexpr()'" config.content;
|
||||
|
||||
Reference in New Issue
Block a user