mirror of
https://github.com/nix-community/nixvim.git
synced 2026-08-24 10:14:03 -05:00
plugins/treesitter: add highlight disable option
This commit is contained in:
@@ -187,6 +187,23 @@ lib.nixvim.plugins.mkNeovimPlugin {
|
||||
|
||||
highlight = {
|
||||
enable = lib.mkEnableOption "tree-sitter based syntax highlighting";
|
||||
|
||||
disable = mkOption {
|
||||
type = with types; listOf str;
|
||||
default = [ ];
|
||||
example = [
|
||||
"latex"
|
||||
"html"
|
||||
];
|
||||
description = ''
|
||||
List of languages or filetypes for which tree-sitter based syntax highlighting should not
|
||||
be started by Nixvim.
|
||||
|
||||
This option only applies to Nixvim's native tree-sitter highlighting setup for the modern
|
||||
nvim-treesitter main branch. Legacy nvim-treesitter configuration should continue using
|
||||
upstream settings under `plugins.treesitter.settings`.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
indent = {
|
||||
@@ -294,14 +311,31 @@ lib.nixvim.plugins.mkNeovimPlugin {
|
||||
''}
|
||||
${optionalString (highlightEnabled || indentEnabled) ''
|
||||
-- Enable features via autocommands for modern nvim-treesitter
|
||||
${optionalString highlightEnabled ''
|
||||
local disabled_highlight = ${lib.nixvim.toLuaObject cfg.highlight.disable}
|
||||
''}
|
||||
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
group = augroup,
|
||||
pattern = '*',
|
||||
callback = function()
|
||||
callback = function(args)
|
||||
${optionalString highlightEnabled ''
|
||||
pcall(vim.treesitter.start)
|
||||
local filetype = vim.bo[args.buf].filetype
|
||||
local lang = vim.treesitter.language.get_lang(filetype) or filetype
|
||||
local start_highlight = true
|
||||
|
||||
for _, disabled in ipairs(disabled_highlight) do
|
||||
if disabled == lang or disabled == filetype then
|
||||
start_highlight = false
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if start_highlight then
|
||||
pcall(vim.treesitter.start, args.buf, lang)
|
||||
end
|
||||
''}${optionalString indentEnabled ''
|
||||
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||
vim.bo[args.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||
''}
|
||||
end,
|
||||
})
|
||||
@@ -343,7 +377,19 @@ lib.nixvim.plugins.mkNeovimPlugin {
|
||||
};
|
||||
|
||||
warnings = lib.nixvim.mkWarnings "plugins.treesitter" (
|
||||
lib.map (packageName: {
|
||||
[
|
||||
{
|
||||
when =
|
||||
(cfg.settings.highlight.disable or null) != null
|
||||
&& !(lib.hasInfix "nvim-treesitter-legacy" (lib.getName cfg.package));
|
||||
message = ''
|
||||
`plugins.treesitter.settings.highlight.disable` is an upstream legacy nvim-treesitter
|
||||
option. For Nixvim's native highlighting support with the modern nvim-treesitter main
|
||||
branch, use `${opt.highlight.disable}` instead.
|
||||
'';
|
||||
}
|
||||
]
|
||||
++ lib.map (packageName: {
|
||||
when = !cfg.nixGrammars && !config.dependencies.${packageName}.enable;
|
||||
message = ''
|
||||
`${packageName}` is required to build grammars as you are not using `${opt.nixGrammars}`.
|
||||
|
||||
@@ -40,6 +40,36 @@
|
||||
};
|
||||
};
|
||||
|
||||
disable-highlighting =
|
||||
{ config, lib, ... }:
|
||||
{
|
||||
assertions = [
|
||||
{
|
||||
assertion = lib.hasInfix ''local disabled_highlight = { "latex", "html" }'' config.content;
|
||||
message = "Treesitter highlight disable list should be present in generated lua.";
|
||||
}
|
||||
{
|
||||
assertion = lib.hasInfix "if disabled == lang or disabled == filetype then" config.content;
|
||||
message = "Treesitter highlight disable check should match language and filetype.";
|
||||
}
|
||||
{
|
||||
assertion = lib.hasInfix "pcall(vim.treesitter.start, args.buf, lang)" config.content;
|
||||
message = "Treesitter highlighting should start with the resolved language.";
|
||||
}
|
||||
];
|
||||
|
||||
plugins.treesitter = {
|
||||
enable = true;
|
||||
highlight = {
|
||||
enable = true;
|
||||
disable = [
|
||||
"latex"
|
||||
"html"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
no-nix-grammars = {
|
||||
plugins.treesitter = {
|
||||
enable = true;
|
||||
@@ -66,6 +96,7 @@
|
||||
legacy-master = {
|
||||
plugins.treesitter = {
|
||||
enable = true;
|
||||
package = pkgs.vimPlugins.nvim-treesitter-legacy;
|
||||
|
||||
settings = {
|
||||
auto_install = false;
|
||||
@@ -100,4 +131,24 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
legacy-highlight-disable-warning = {
|
||||
test.runNvim = false;
|
||||
test.warnings = expect: [
|
||||
(expect "count" 1)
|
||||
(expect "any" "`plugins.treesitter.settings.highlight.disable` is an upstream legacy nvim-treesitter")
|
||||
(expect "any" "use `plugins.treesitter.highlight.disable` instead.")
|
||||
];
|
||||
|
||||
plugins.treesitter = {
|
||||
enable = true;
|
||||
settings.highlight = {
|
||||
enable = true;
|
||||
disable = [
|
||||
"latex"
|
||||
"html"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user