mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2024-11-09 14:45:58 +01:00
plugins/treesitter: allow highlight
to be fine-grained
This commit is contained in:
parent
49b705b6aa
commit
5e08ed42e7
2 changed files with 42 additions and 4 deletions
|
@ -6,7 +6,9 @@
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.modules) mkIf mkMerge;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
inherit (lib.lists) optional;
|
inherit (lib.lists) optional;
|
||||||
|
inherit (lib.trivial) boolToString;
|
||||||
inherit (lib.nvim.binds) mkSetBinding addDescriptionsToMappings;
|
inherit (lib.nvim.binds) mkSetBinding addDescriptionsToMappings;
|
||||||
|
inherit (lib.nvim.lua) toLuaObject;
|
||||||
inherit (lib.nvim.dag) entryBefore entryAnywhere;
|
inherit (lib.nvim.dag) entryBefore entryAnywhere;
|
||||||
|
|
||||||
cfg = config.vim.treesitter;
|
cfg = config.vim.treesitter;
|
||||||
|
@ -50,8 +52,8 @@ in {
|
||||||
ensure_installed = {},
|
ensure_installed = {},
|
||||||
|
|
||||||
highlight = {
|
highlight = {
|
||||||
enable = true,
|
enable = ${boolToString cfg.highlight.enable},
|
||||||
disable = {},
|
disable = ${toLuaObject cfg.highlight.disable},
|
||||||
},
|
},
|
||||||
|
|
||||||
incremental_selection = {
|
incremental_selection = {
|
||||||
|
|
|
@ -3,9 +3,10 @@
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.options) mkOption mkEnableOption;
|
inherit (lib.options) mkOption mkEnableOption literalMD;
|
||||||
inherit (lib.nvim.binds) mkMappingOption;
|
inherit (lib.nvim.binds) mkMappingOption;
|
||||||
inherit (lib.types) listOf package;
|
inherit (lib.types) listOf package str either;
|
||||||
|
inherit (lib.nvim.types) luaInline;
|
||||||
|
|
||||||
inherit (pkgs.vimPlugins.nvim-treesitter) builtGrammars;
|
inherit (pkgs.vimPlugins.nvim-treesitter) builtGrammars;
|
||||||
in {
|
in {
|
||||||
|
@ -33,6 +34,41 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
highlight = {
|
||||||
|
enable = mkEnableOption "highlighting with treesitter";
|
||||||
|
disable = mkOption {
|
||||||
|
type = either (luaInline (listOf str));
|
||||||
|
default = [];
|
||||||
|
example = literalMD ''
|
||||||
|
```lua
|
||||||
|
-- Disable slow treesitter highlight for large files
|
||||||
|
disable = function(lang, buf)
|
||||||
|
local max_filesize = 1000 * 1024 -- 1MB
|
||||||
|
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
|
||||||
|
if ok and stats and stats.size > max_filesize then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
'';
|
||||||
|
|
||||||
|
description = ''
|
||||||
|
List of treesitter grammars to disable highlighting for.
|
||||||
|
|
||||||
|
This option can be either a list, in which case it will be
|
||||||
|
converted to a Lua table containing grammars to disable
|
||||||
|
highlighting for, or a string containing a **lua function**
|
||||||
|
that will be read as is.
|
||||||
|
|
||||||
|
::: {.warning}
|
||||||
|
A comma will be added at the end of your function, so you
|
||||||
|
do not need to add it yourself. Doing so will cause in
|
||||||
|
syntax errors within your Neovim configuration.
|
||||||
|
:::
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
defaultGrammars = mkOption {
|
defaultGrammars = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
|
Loading…
Reference in a new issue