Compare commits

...

3 commits

Author SHA1 Message Date
NotAShelf
aa592783c7
Merge 616c00ab46 into 4b868d0de6 2024-04-25 12:08:30 +00:00
616c00ab46
plugins/treesitter: generate Lua configuration from Nix 2024-04-28 21:04:28 +03:00
4b868d0de6
wrapper/rc: loop over removed runtime paths
Would be neat to expose removed paths as a list in the future
2024-04-23 21:10:39 +03:00
3 changed files with 132 additions and 49 deletions

View file

@ -60,15 +60,15 @@ in {
-- Indentation module for Treesitter -- Indentation module for Treesitter
indent = { indent = {
enable = true, enable = ${toLuaObject cfg.indent.enable},
disable = {}, disable = ${toLuaObject cfg.indent.disable},
}, },
-- Highlight module for Treesitter -- Highlight module for Treesitter
highlight = { highlight = {
enable = ${boolToString cfg.highlight.enable}, enable = ${toLuaObject cfg.highlight.enable},
disable = ${toLuaObject cfg.highlight.disable}, disable = ${toLuaObject cfg.highlight.disable},
additional_vim_regex_highlighting = false, additional_vim_regex_highlighting = ${toLuaObject cfg.highlight.additionalVimRegexHighlighting},
}, },
-- Indentation module for Treesitter -- Indentation module for Treesitter
@ -76,13 +76,14 @@ in {
-- handled by `vim.maps` entries calling lua -- handled by `vim.maps` entries calling lua
-- functions achieving the same functionality. -- functions achieving the same functionality.
incremental_selection = { incremental_selection = {
enable = true, enable = ${toLuaObject cfg.incrementalSelection.enable},
disable = {}, disable = ${toLuaObject cfg.incrementalSelection.disable},
keymaps = { keymaps = {
init_selection = false, init_selection = false,
node_incremental = false, node_incremental = false,
scope_incremental = false, scope_incremental = false,
node_decremental = false, node_decremental = false,
}, },
}, },
} }

View file

@ -3,7 +3,7 @@
lib, lib,
... ...
}: let }: let
inherit (lib.options) mkOption mkEnableOption literalMD; inherit (lib.options) mkOption mkEnableOption literalMD literalExpression;
inherit (lib.types) listOf package str either bool; inherit (lib.types) listOf package str either bool;
inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) luaInline; inherit (lib.nvim.types) luaInline;
@ -20,6 +20,7 @@ in {
fold = mkEnableOption "fold with treesitter"; fold = mkEnableOption "fold with treesitter";
autotagHtml = mkEnableOption "autoclose and rename html tag"; autotagHtml = mkEnableOption "autoclose and rename html tag";
grammars = mkOption { grammars = mkOption {
type = listOf package; type = listOf package;
default = []; default = [];
@ -32,41 +33,6 @@ in {
''; '';
}; };
highlight = {
enable = mkEnableOption "highlighting with treesitter";
disable = mkOption {
type = either (listOf str) luaInline;
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.
:::
'';
};
};
addDefaultGrammars = mkOption { addDefaultGrammars = mkOption {
type = bool; type = bool;
default = true; default = true;
@ -97,5 +63,106 @@ in {
::: :::
''; '';
}; };
indent = {
enable = mkEnableOption "indentation with treesitter" // {default = true;};
disable = mkOption {
type = either (listOf str) luaInline;
default = [];
example = literalExpression ''["c" "rust"]'';
description = ''
List of treesitter grammars to disable indentation for.
This option can be either a list, in which case it will be
converted to a Lua table containing grammars to disable
indentation 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.
:::
'';
};
};
highlight = {
enable = mkEnableOption "highlighting with treesitter" // {default = true;};
disable = mkOption {
type = either (listOf str) luaInline;
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.
:::
'';
};
additionalVimRegexHighlighting = mkOption {
type = either bool (listOf str);
default = false;
description = ''
Takes either a boolean or a list of languages.
Setting this to true will run `:h syntax` and tree-sitter at the same time.
You may this to `true` if you depend on 'syntax' being enabled (like for
indentation).
::: {.note}
Using this option may slow down your editor, and you may see some duplicate
highlights.
:::
'';
};
};
incrementalSelection = {
enable = mkEnableOption "incremental selection with treesitter" // {default = true;};
disable = mkOption {
type = either (listOf str) luaInline;
default = [];
example = literalExpression ''["c" "rust" ]'';
description = ''
List of treesitter grammars to disable incremental selection
for.
This option can be either a list, in which case it will be
converted to a Lua table containing grammars to disable
indentation 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.
:::
'';
};
};
}; };
} }

View file

@ -49,8 +49,17 @@ in {
default = []; default = [];
example = literalExpression '' example = literalExpression ''
[ [
"$HOME/.config/nvim-extra" # absolute path, as a string - impure # absolute path, as a string - impure
./nvim # relative path, as a path - pure "$HOME/.config/nvim-extra"
# relative path, as a path - pure
./nvim
# source type path - pure and reproducible
(builtins.source {
path = ./runtime;
name = "nvim-runtime";
})
] ]
''; '';
@ -124,9 +133,15 @@ in {
-- Remove default user runtime paths from the -- Remove default user runtime paths from the
-- `runtimepath` option to avoid leaking user configuration -- `runtimepath` option to avoid leaking user configuration
-- into the final neovim wrapper -- into the final neovim wrapper
vim.opt.runtimepath:remove(vim.fn.stdpath('config')) -- $HOME/.config/nvim local defaultRuntimePaths = {
vim.opt.runtimepath:remove(vim.fn.stdpath('config') .. "/after") -- $HOME/.config/nvim/after vim.fn.stdpath('config'), -- $HOME/.config/nvim
vim.opt.runtimepath:remove(vim.fn.stdpath('data') .. "/site") -- $HOME/.local/share/nvim/site vim.fn.stdpath('config') .. "/after", -- $HOME/.config/nvim/after
vim.fn.stdpath('data') .. "/site", -- $HOME/.local/share/nvim/site
}
for _, path in ipairs(defaultRuntimePaths) do
vim.opt.runtimepath:remove(path)
end
''} ''}
${optionalString cfg.enableLuaLoader "vim.loader.enable()"} ${optionalString cfg.enableLuaLoader "vim.loader.enable()"}
@ -134,9 +149,9 @@ in {
defaultText = literalMD '' defaultText = literalMD ''
By default, this option will **append** paths in By default, this option will **append** paths in
[vim.additionalRuntimePaths](#opt-vim.additionalRuntimePaths) [](#opt-vim.additionalRuntimePaths)
to the `runtimepath` and enable the experimental Lua module loader to the `runtimepath` and enable the experimental Lua module loader
if [vim.enableLuaLoader](#opt-vim.enableLuaLoader) is set to true. if [](#opt-vim.enableLuaLoader) is set to true.
''; '';
example = literalExpression ''"$${builtins.readFile ./my-lua-config-pre.lua}"''; example = literalExpression ''"$${builtins.readFile ./my-lua-config-pre.lua}"'';