mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-01-16 07:27:47 +00:00
Compare commits
No commits in common. "ceaae0eb2ece9e06159d6de80b0709e38d77f6a4" and "c1713898c44cab30072b93635a6bf897b4002138" have entirely different histories.
ceaae0eb2e
...
c1713898c4
4 changed files with 187 additions and 82 deletions
|
|
@ -4,8 +4,12 @@
|
||||||
|
|
||||||
- Nixpkgs has merged a fully incompatible rewrite of
|
- Nixpkgs has merged a fully incompatible rewrite of
|
||||||
`vimPlugins.nvim-treesitter`. Namely, it changes from the frozen `master`
|
`vimPlugins.nvim-treesitter`. Namely, it changes from the frozen `master`
|
||||||
branch to the new main branch. This change removes incremental selections, so
|
branch to the new main branch. This change also affects how grammars are
|
||||||
it is no longer available.
|
built, and forces us to change a few things around.
|
||||||
|
- We must now use `"nvim-treesitter".setup` over the old `.configs`.
|
||||||
|
Additionally, built grammars **no longer include queries by default**,
|
||||||
|
therefore queries not managed by nvf will lack their respective syntax
|
||||||
|
highlighting capabilities.
|
||||||
|
|
||||||
## Changelog {#sec-release-0-9-changelog}
|
## Changelog {#sec-release-0-9-changelog}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -308,39 +308,5 @@ in {
|
||||||
])
|
])
|
||||||
# Migrated via batchRenameOptions. Further batch renames must be below this line.
|
# Migrated via batchRenameOptions. Further batch renames must be below this line.
|
||||||
renamedVimOpts
|
renamedVimOpts
|
||||||
|
|
||||||
# 2026-01-06
|
|
||||||
[
|
|
||||||
(mkRemovedOptionModule ["vim" "treesitter" "highlight" "disable"] ''
|
|
||||||
Treesitter highlighting is now handled by Neovim natively, and it does not have a disable option.
|
|
||||||
'')
|
|
||||||
(mkRemovedOptionModule ["vim" "treesitter" "highlight" "additionalVimRegexHighlighting"] ''
|
|
||||||
Treesitter highlighting is now handled by Neovim natively, and it does not have a additionalVimRegexHighlighting option.
|
|
||||||
'')
|
|
||||||
(mkRemovedOptionModule ["vim" "treesitter" "indent" "disable"] ''
|
|
||||||
Treesitter indentation is now handled differently, and it does not have a disable option.
|
|
||||||
'')
|
|
||||||
(mkRemovedOptionModule ["vim" "treesitter" "incrementalSelection" "enable"] ''
|
|
||||||
Incremental selection configuration has been removed from nvim-treesitter.
|
|
||||||
'')
|
|
||||||
(mkRemovedOptionModule ["vim" "treesitter" "incrementalSelection" "disable"] ''
|
|
||||||
Incremental selection configuration has been removed from nvim-treesitter.
|
|
||||||
'')
|
|
||||||
(mkRemovedOptionModule ["vim" "treesitter" "mappings" "incrementalSelection" "init"] ''
|
|
||||||
Incremental selection configuration has been removed from nvim-treesitter.
|
|
||||||
'')
|
|
||||||
(mkRemovedOptionModule ["vim" "treesitter" "mappings" "incrementalSelection" "incrementByNode"] ''
|
|
||||||
Incremental selection configuration has been removed from nvim-treesitter.
|
|
||||||
'')
|
|
||||||
(
|
|
||||||
mkRemovedOptionModule ["vim" "treesitter" "mappings" "incrementalSelection" "incrementByScope"]
|
|
||||||
''
|
|
||||||
Incremental selection configuration has been removed from nvim-treesitter.
|
|
||||||
''
|
|
||||||
)
|
|
||||||
(mkRemovedOptionModule ["vim" "treesitter" "mappings" "incrementalSelection" "decrementByNode"] ''
|
|
||||||
Incremental selection configuration has been removed from nvim-treesitter.
|
|
||||||
'')
|
|
||||||
]
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,19 @@
|
||||||
{
|
{
|
||||||
config,
|
config,
|
||||||
lib,
|
lib,
|
||||||
|
options,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.modules) mkIf;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
inherit (lib.lists) optionals;
|
inherit (lib.lists) optionals;
|
||||||
inherit (lib.nvim.dag) entryAfter;
|
inherit (lib.nvim.binds) mkSetBinding addDescriptionsToMappings;
|
||||||
|
inherit (lib.nvim.lua) toLuaObject;
|
||||||
|
inherit (lib.nvim.dag) entryBefore entryAfter;
|
||||||
|
|
||||||
cfg = config.vim.treesitter;
|
cfg = config.vim.treesitter;
|
||||||
|
|
||||||
|
mappingDefinitions = options.vim.treesitter.mappings;
|
||||||
|
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions;
|
||||||
in {
|
in {
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
vim = {
|
vim = {
|
||||||
|
|
@ -21,46 +27,68 @@ in {
|
||||||
|
|
||||||
treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars;
|
treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars;
|
||||||
|
|
||||||
pluginRC.treesitter-autocommands = entryAfter ["basic"] ''
|
maps = {
|
||||||
vim.api.nvim_create_augroup("nvf_treesitter", { clear = true })
|
# HACK: Using mkSetLuaBinding and putting the lua code does not work for some reason: It just selects the whole file.
|
||||||
|
# This works though, and if it ain't broke, don't fix it.
|
||||||
|
normal = mkSetBinding mappings.incrementalSelection.init ":lua require('nvim-treesitter.incremental_selection').init_selection()<CR>";
|
||||||
|
|
||||||
${lib.optionalString cfg.highlight.enable ''
|
visualOnly = mkMerge [
|
||||||
-- Enable treesitter highlighting for all filetypes
|
(mkSetBinding mappings.incrementalSelection.incrementByNode "<cmd>lua require('nvim-treesitter.incremental_selection').node_incremental()<CR>")
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
(mkSetBinding mappings.incrementalSelection.incrementByScope "<cmd>lua require('nvim-treesitter.incremental_selection').scope_incremental()<CR>")
|
||||||
group = "nvf_treesitter",
|
(mkSetBinding mappings.incrementalSelection.decrementByNode "<cmd>lua require('nvim-treesitter.incremental_selection').node_decremental()<CR>")
|
||||||
pattern = "*",
|
];
|
||||||
callback = function()
|
};
|
||||||
pcall(vim.treesitter.start)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
''}
|
|
||||||
|
|
||||||
${lib.optionalString cfg.indent.enable ''
|
# For some reason treesitter highlighting does not work on start if this is set before syntax on
|
||||||
-- Enable treesitter highlighting for all filetypes
|
pluginRC.treesitter-fold = mkIf cfg.fold (entryBefore ["basic"] ''
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
-- This is required by treesitter-context to handle folds
|
||||||
group = "nvf_treesitter",
|
vim.o.foldmethod = "expr"
|
||||||
pattern = "*",
|
vim.o.foldexpr = "nvim_treesitter#foldexpr()"
|
||||||
callback = function()
|
|
||||||
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
''}
|
|
||||||
|
|
||||||
${lib.optionalString cfg.fold ''
|
-- This is optional, but is set rather as a sane default.
|
||||||
-- Enable treesitter folding for all filetypes
|
-- If unset, opened files will be folded by automatically as
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
-- the files are opened
|
||||||
group = "nvf_treesitter",
|
vim.o.foldenable = false
|
||||||
pattern = "*",
|
'');
|
||||||
callback = function()
|
|
||||||
vim.wo[0][0].foldmethod = "expr"
|
pluginRC.treesitter = entryAfter ["basic"] ''
|
||||||
vim.wo[0][0].foldexpr = "v:lua.vim.treesitter.foldexpr()"
|
require('nvim-treesitter.config').setup {
|
||||||
-- This is optional, but is set rather as a sane default.
|
-- Disable imperative treesitter options that would attempt to fetch
|
||||||
-- If unset, opened files will be folded by automatically as
|
-- grammars into the read-only Nix store. To add additional grammars here
|
||||||
-- the files are opened
|
-- you must use the `config.vim.treesitter.grammars` option.
|
||||||
vim.o.foldenable = false
|
auto_install = false,
|
||||||
end,
|
sync_install = false,
|
||||||
})
|
ensure_installed = {},
|
||||||
''}
|
|
||||||
|
-- Indentation module for Treesitter
|
||||||
|
indent = {
|
||||||
|
enable = ${toLuaObject cfg.indent.enable},
|
||||||
|
disable = ${toLuaObject cfg.indent.disable},
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Highlight module for Treesitter
|
||||||
|
highlight = {
|
||||||
|
enable = ${toLuaObject cfg.highlight.enable},
|
||||||
|
disable = ${toLuaObject cfg.highlight.disable},
|
||||||
|
additional_vim_regex_highlighting = ${toLuaObject cfg.highlight.additionalVimRegexHighlighting},
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Indentation module for Treesitter
|
||||||
|
-- Keymaps are set to false here as they are
|
||||||
|
-- handled by `vim.maps` entries calling lua
|
||||||
|
-- functions achieving the same functionality.
|
||||||
|
incremental_selection = {
|
||||||
|
enable = ${toLuaObject cfg.incrementalSelection.enable},
|
||||||
|
disable = ${toLuaObject cfg.incrementalSelection.disable},
|
||||||
|
keymaps = {
|
||||||
|
init_selection = false,
|
||||||
|
node_incremental = false,
|
||||||
|
scope_incremental = false,
|
||||||
|
node_decremental = false,
|
||||||
|
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,21 @@
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.options) mkOption mkEnableOption literalExpression;
|
inherit (lib.options) mkOption mkEnableOption literalMD literalExpression;
|
||||||
inherit (lib.types) listOf package bool;
|
inherit (lib.types) listOf package str either bool;
|
||||||
|
inherit (lib.nvim.binds) mkMappingOption;
|
||||||
|
inherit (lib.nvim.types) luaInline;
|
||||||
in {
|
in {
|
||||||
options.vim.treesitter = {
|
options.vim.treesitter = {
|
||||||
enable = mkEnableOption "treesitter, also enabled automatically through language options";
|
enable = mkEnableOption "treesitter, also enabled automatically through language options";
|
||||||
|
|
||||||
|
mappings.incrementalSelection = {
|
||||||
|
init = mkMappingOption "Init selection [treesitter]" "gnn";
|
||||||
|
incrementByNode = mkMappingOption "Increment selection by node [treesitter]" "grn";
|
||||||
|
incrementByScope = mkMappingOption "Increment selection by scope [treesitter]" "grc";
|
||||||
|
decrementByNode = mkMappingOption "Decrement selection by node [treesitter]" "grm";
|
||||||
|
};
|
||||||
|
|
||||||
fold = mkEnableOption "fold with treesitter";
|
fold = mkEnableOption "fold with treesitter";
|
||||||
autotagHtml = mkEnableOption "autoclose and rename html tag";
|
autotagHtml = mkEnableOption "autoclose and rename html tag";
|
||||||
|
|
||||||
|
|
@ -16,14 +25,14 @@ in {
|
||||||
type = listOf package;
|
type = listOf package;
|
||||||
default = [];
|
default = [];
|
||||||
example = literalExpression ''
|
example = literalExpression ''
|
||||||
with pkgs.vimPlugins.nvim-treesitter.parsers; [
|
with pkgs.vimPlugins.nvim-treesitter.grammarPlugins; [
|
||||||
regex
|
regex
|
||||||
kdl
|
kdl
|
||||||
];
|
];
|
||||||
'';
|
'';
|
||||||
description = ''
|
description = ''
|
||||||
List of treesitter grammars to install. For grammars to be installed properly,
|
List of treesitter grammars to install. For grammars to be installed properly,
|
||||||
you must use grammars from `pkgs.vimPlugins.nvim-treesitter.parsers` or `pkgs.vimPlugins.nvim-treesitter.grammarPlugins`.
|
you must use grammars from `pkgs.vimPlugins.nvim-treesitter.grammarPlugins`.
|
||||||
You can use `pkgs.vimPlugins.nvim-treesitter.allGrammars` to install all grammars.
|
You can use `pkgs.vimPlugins.nvim-treesitter.allGrammars` to install all grammars.
|
||||||
|
|
||||||
For languages already supported by nvf, you may use
|
For languages already supported by nvf, you may use
|
||||||
|
|
@ -47,7 +56,7 @@ in {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = listOf package;
|
type = listOf package;
|
||||||
default = with pkgs.vimPlugins.nvim-treesitter.parsers; [c lua vim vimdoc query];
|
default = with pkgs.vimPlugins.nvim-treesitter.grammarPlugins; [c lua vim vimdoc query];
|
||||||
description = ''
|
description = ''
|
||||||
A list of treesitter grammars that will be installed by default
|
A list of treesitter grammars that will be installed by default
|
||||||
if treesitter has been enabled and {option}`vim.treeesitter.addDefaultGrammars`
|
if treesitter has been enabled and {option}`vim.treeesitter.addDefaultGrammars`
|
||||||
|
|
@ -64,7 +73,105 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
indent = {enable = mkEnableOption "indentation with treesitter" // {default = true;};};
|
indent = {
|
||||||
highlight = {enable = mkEnableOption "highlighting with treesitter" // {default = true;};};
|
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
|
||||||
|
function(lang, buf)
|
||||||
|
local max_filesize = 1000 * 1024 -- 1MB
|
||||||
|
local ok, stats = pcall(vim.uv.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.
|
||||||
|
:::
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue