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;
|
2024-04-23 17:20:49 +00:00
|
|
|
inherit (lib.lists) optional optionals;
|
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-04-24 20:34:39 +00:00
|
|
|
inherit (lib.nvim.dag) entryBefore entryAfter;
|
2023-11-07 00:50:27 +00:00
|
|
|
|
2023-02-28 09:01:56 +00:00
|
|
|
cfg = config.vim.treesitter;
|
2024-10-09 17:50:34 +00:00
|
|
|
usingNvimCmp = config.vim.autocomplete.nvim-cmp.enable;
|
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";
|
|
|
|
|
2024-10-09 17:50:34 +00:00
|
|
|
autocomplete.nvim-cmp.sources = {treesitter = "[Treesitter]";};
|
2024-04-23 17:20:49 +00:00
|
|
|
treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars;
|
2024-03-15 11:19:11 +00:00
|
|
|
|
|
|
|
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 [
|
2024-05-02 10:37:44 +00:00
|
|
|
(mkSetBinding mappings.incrementalSelection.incrementByNode "<cmd>lua require('nvim-treesitter.incremental_selection').node_incremental()<CR>")
|
|
|
|
(mkSetBinding mappings.incrementalSelection.incrementByScope "<cmd>lua require('nvim-treesitter.incremental_selection').scope_incremental()<CR>")
|
|
|
|
(mkSetBinding mappings.incrementalSelection.decrementByNode "<cmd>lua require('nvim-treesitter.incremental_selection').node_decremental()<CR>")
|
2024-03-15 11:19:11 +00:00
|
|
|
];
|
|
|
|
};
|
2024-04-23 17:20:49 +00:00
|
|
|
|
2024-04-24 22:36:58 +00:00
|
|
|
# For some reason treesitter highlighting does not work on start if this is set before syntax on
|
2024-07-20 08:30:48 +00:00
|
|
|
pluginRC.treesitter-fold = mkIf cfg.fold (entryBefore ["basic"] ''
|
|
|
|
-- This is required by treesitter-context to handle folds
|
|
|
|
vim.o.foldmethod = "expr"
|
|
|
|
vim.o.foldexpr = "nvim_treesitter#foldexpr()"
|
|
|
|
|
|
|
|
-- This is optional, but is set rather as a sane default.
|
|
|
|
-- If unset, opened files will be folded by automatically as
|
|
|
|
-- the files are opened
|
|
|
|
vim.o.foldenable = false
|
2024-03-15 11:19:11 +00:00
|
|
|
'');
|
|
|
|
|
2024-07-20 08:30:48 +00:00
|
|
|
pluginRC.treesitter = entryAfter ["basic"] ''
|
2024-04-23 17:20:49 +00:00
|
|
|
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-04-23 17:20:49 +00:00
|
|
|
-- Indentation module for Treesitter
|
|
|
|
indent = {
|
2024-04-28 18:04:28 +00:00
|
|
|
enable = ${toLuaObject cfg.indent.enable},
|
|
|
|
disable = ${toLuaObject cfg.indent.disable},
|
2024-04-23 17:20:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
-- Highlight module for Treesitter
|
2024-03-15 11:19:11 +00:00
|
|
|
highlight = {
|
2024-04-28 18:04:28 +00:00
|
|
|
enable = ${toLuaObject cfg.highlight.enable},
|
2024-04-23 13:48:39 +00:00
|
|
|
disable = ${toLuaObject cfg.highlight.disable},
|
2024-04-28 18:04:28 +00:00
|
|
|
additional_vim_regex_highlighting = ${toLuaObject cfg.highlight.additionalVimRegexHighlighting},
|
2024-03-15 11:19:11 +00:00
|
|
|
},
|
|
|
|
|
2024-04-23 17:20:49 +00:00
|
|
|
-- Indentation module for Treesitter
|
2024-04-28 17:19:25 +00:00
|
|
|
-- Keymaps are set to false here as they are
|
|
|
|
-- handled by `vim.maps` entries calling lua
|
|
|
|
-- functions achieving the same functionality.
|
2024-03-15 11:19:11 +00:00
|
|
|
incremental_selection = {
|
2024-04-28 18:04:28 +00:00
|
|
|
enable = ${toLuaObject cfg.incrementalSelection.enable},
|
|
|
|
disable = ${toLuaObject cfg.incrementalSelection.disable},
|
2024-03-15 11:19:11 +00:00
|
|
|
keymaps = {
|
|
|
|
init_selection = false,
|
|
|
|
node_incremental = false,
|
|
|
|
scope_incremental = false,
|
|
|
|
node_decremental = false,
|
2024-04-28 18:04:28 +00:00
|
|
|
|
2024-03-15 11:19:11 +00:00
|
|
|
},
|
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
|
|
|
}
|