2023-02-28 09:01:56 +00:00
|
|
|
{
|
|
|
|
config,
|
2024-04-23 13:08:55 +00:00
|
|
|
pkgs,
|
2023-02-28 09:01:56 +00:00
|
|
|
lib,
|
|
|
|
...
|
2023-11-07 00:50:27 +00:00
|
|
|
}: let
|
2024-03-15 11:19:11 +00:00
|
|
|
inherit (lib.modules) mkIf mkMerge;
|
|
|
|
inherit (lib.lists) optional;
|
2024-04-23 13:48:39 +00:00
|
|
|
inherit (lib.trivial) boolToString;
|
2024-03-15 11:19:11 +00:00
|
|
|
inherit (lib.nvim.binds) mkSetBinding addDescriptionsToMappings;
|
2024-04-23 13:48:39 +00:00
|
|
|
inherit (lib.nvim.lua) toLuaObject;
|
2024-03-15 11:19:11 +00:00
|
|
|
inherit (lib.nvim.dag) entryBefore entryAnywhere;
|
2023-11-07 00:50:27 +00:00
|
|
|
|
2023-02-28 09:01:56 +00:00
|
|
|
cfg = config.vim.treesitter;
|
2023-04-17 20:27:27 +00:00
|
|
|
usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp";
|
2023-05-02 22:15:05 +00:00
|
|
|
|
2024-04-23 13:08:55 +00:00
|
|
|
self = import ./treesitter.nix {inherit pkgs lib;};
|
2023-05-02 22:15:05 +00:00
|
|
|
mappingDefinitions = self.options.vim.treesitter.mappings;
|
|
|
|
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions;
|
2023-02-28 09:01:56 +00:00
|
|
|
in {
|
2023-04-17 20:27:27 +00:00
|
|
|
config = mkIf cfg.enable {
|
2024-03-15 11:19:11 +00:00
|
|
|
vim = {
|
|
|
|
startPlugins = ["nvim-treesitter"] ++ optional usingNvimCmp "cmp-treesitter";
|
|
|
|
|
|
|
|
autocomplete.sources = {"treesitter" = "[Treesitter]";};
|
|
|
|
|
|
|
|
maps = {
|
|
|
|
# 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>";
|
|
|
|
|
|
|
|
visualOnly = mkMerge [
|
|
|
|
(mkSetBinding mappings.incrementalSelection.incrementByNode ":lua require('nvim-treesitter.incremental_selection').node_incremental()<CR>")
|
|
|
|
(mkSetBinding mappings.incrementalSelection.incrementByScope ":lua require('nvim-treesitter.incremental_selection').scope_incremental()<CR>")
|
|
|
|
(mkSetBinding mappings.incrementalSelection.decrementByNode ":lua require('nvim-treesitter.incremental_selection').node_decremental()<CR>")
|
|
|
|
];
|
|
|
|
};
|
|
|
|
# For some reason treesitter highlighting does not work on start if this is set before syntax on
|
|
|
|
configRC.treesitter-fold = mkIf cfg.fold (entryBefore ["basic"] ''
|
|
|
|
set foldmethod=expr
|
|
|
|
set foldexpr=nvim_treesitter#foldexpr()
|
|
|
|
set nofoldenable
|
|
|
|
'');
|
|
|
|
|
|
|
|
luaConfigRC.treesitter = entryAnywhere ''
|
|
|
|
require'nvim-treesitter.configs'.setup {
|
2024-04-23 13:08:55 +00:00
|
|
|
-- Disable imperative treesitter options that would attempt to fetch
|
2024-04-23 13:24:00 +00:00
|
|
|
-- grammars into the read-only Nix store. To add additional grammars here
|
2024-04-23 13:08:55 +00:00
|
|
|
-- you must use the `config.vim.treesitter.grammars` option.
|
|
|
|
auto_install = false,
|
|
|
|
sync_install = false,
|
|
|
|
ensure_installed = {},
|
|
|
|
|
2024-03-15 11:19:11 +00:00
|
|
|
highlight = {
|
2024-04-23 13:48:39 +00:00
|
|
|
enable = ${boolToString cfg.highlight.enable},
|
|
|
|
disable = ${toLuaObject cfg.highlight.disable},
|
2024-03-15 11:19:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
incremental_selection = {
|
|
|
|
enable = true,
|
|
|
|
keymaps = {
|
|
|
|
init_selection = false,
|
|
|
|
node_incremental = false,
|
|
|
|
scope_incremental = false,
|
|
|
|
node_decremental = false,
|
|
|
|
},
|
2023-02-28 09:01:56 +00:00
|
|
|
},
|
2024-03-15 11:19:11 +00:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2023-04-17 20:27:27 +00:00
|
|
|
};
|
2023-02-28 09:01:56 +00:00
|
|
|
}
|