treewide: begin restructuring the module tree

This commit is contained in:
raf 2024-04-07 17:16:08 +03:00
commit 7c730a78e5
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
254 changed files with 749 additions and 664 deletions

View file

@ -0,0 +1,66 @@
{
config,
lib,
...
}: let
inherit (lib.modules) mkIf mkMerge;
inherit (lib.lists) optional;
inherit (lib.nvim.binds) mkSetBinding addDescriptionsToMappings;
inherit (lib.nvim.dag) entryBefore entryAnywhere;
cfg = config.vim.treesitter;
usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp";
self = import ./treesitter.nix {inherit lib;};
mappingDefinitions = self.options.vim.treesitter.mappings;
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions;
in {
config = mkIf cfg.enable {
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 {
highlight = {
enable = true,
disable = {},
},
auto_install = false,
ensure_installed = {},
incremental_selection = {
enable = true,
keymaps = {
init_selection = false,
node_incremental = false,
scope_incremental = false,
node_decremental = false,
},
},
}
'';
};
};
}

View file

@ -0,0 +1,89 @@
{
config,
lib,
...
}: let
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) int bool str nullOr enum;
inherit (lib.modules) mkIf;
inherit (lib.trivial) boolToString;
inherit (lib.nvim.lua) nullString;
inherit (lib.nvim.dag) entryAnywhere;
inherit (config.vim) treesitter;
cfg = treesitter.context;
in {
options.vim.treesitter.context = {
enable = mkEnableOption "context of current buffer contents [nvim-treesitter-context] ";
maxLines = mkOption {
description = "How many lines the window should span. Values &lt;=0 mean no limit.";
type = int;
default = 0;
};
minWindowHeight = mkOption {
description = "Minimum editor window height to enable context. Values &lt;= 0 mean no limit.";
type = int;
default = 0;
};
lineNumbers = mkOption {
description = "";
type = bool;
default = true;
};
multilineThreshold = mkOption {
description = "Maximum number of lines to collapse for a single context line.";
type = int;
default = 20;
};
trimScope = mkOption {
description = "Which context lines to discard if [](#opt-vim.treesitter.context.maxLines) is exceeded.";
type = enum ["inner" "outer"];
default = "outer";
};
mode = mkOption {
description = "Line used to calculate context.";
type = enum ["cursor" "topline"];
default = "cursor";
};
separator = mkOption {
description = ''
Separator between context and content. Should be a single character string, like '-'.
When separator is set, the context will only show up when there are at least 2 lines above cursorline.
'';
type = nullOr str;
default = null;
};
zindex = mkOption {
description = "The Z-index of the context window.";
type = int;
default = 20;
};
};
config = mkIf (treesitter.enable && cfg.enable) {
vim.startPlugins = ["nvim-treesitter-context"];
vim.luaConfigRC.treesitter-context = entryAnywhere ''
require'treesitter-context'.setup {
enable = true,
max_lines = ${toString cfg.maxLines},
min_window_height = ${toString cfg.minWindowHeight},
line_numbers = ${boolToString cfg.lineNumbers},
multiline_threshold = ${toString cfg.multilineThreshold},
trim_scope = '${cfg.trimScope}',
mode = '${cfg.mode}',
separator = ${nullString cfg.separator},
max_lines = ${toString cfg.zindex},
}
'';
};
}

View file

@ -0,0 +1,7 @@
{
imports = [
./treesitter.nix
./context.nix
./config.nix
];
}

View file

@ -0,0 +1,26 @@
{lib, ...}: let
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.types) listOf package;
in {
options.vim.treesitter = {
enable = mkEnableOption "treesitter, also enabled automatically through language options";
fold = mkEnableOption "fold with treesitter";
autotagHtml = mkEnableOption "autoclose and rename html tag";
grammars = mkOption {
type = listOf package;
default = [];
description = ''
List of treesitter grammars to install. For supported languages
use the `vim.language.<lang>.treesitter` option
'';
};
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";
};
};
}