Compare commits

...

3 Commits

Author SHA1 Message Date
NotAShelf b44d53bbae
Merge c8d38872ab into 4b868d0de6 2024-04-25 11:20:18 +00:00
NotAShelf c8d38872ab
plugins/treesitter: migrate treesitter-context to new `setupOpts` 2024-04-28 20:19:25 +03:00
NotAShelf 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
5 changed files with 116 additions and 66 deletions

View File

@ -39,8 +39,13 @@ in {
# For some reason treesitter highlighting does not work on start if this is set before syntax on # 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"] '' configRC.treesitter-fold = mkIf cfg.fold (entryBefore ["basic"] ''
" This is required by treesitter-context to handle folds
set foldmethod=expr set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr() set 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
set nofoldenable set nofoldenable
''); '');
@ -67,6 +72,9 @@ in {
}, },
-- Indentation module for Treesitter -- 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 = { incremental_selection = {
enable = true, enable = true,
disable = {}, disable = {},

View File

@ -6,7 +6,7 @@
inherit (lib.options) mkOption mkEnableOption literalMD; inherit (lib.options) mkOption mkEnableOption literalMD;
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 mkGrammarOption; 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";

View File

@ -4,28 +4,21 @@
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.trivial) boolToString; inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.lua) nullString;
inherit (lib.nvim.dag) entryAfter; inherit (lib.nvim.dag) entryAfter;
inherit (config.vim) treesitter; inherit (config.vim) treesitter;
cfg = treesitter.context; cfg = treesitter.context;
in { in {
config = mkIf (treesitter.enable && cfg.enable) { config = mkIf (treesitter.enable && cfg.enable) {
vim.startPlugins = ["nvim-treesitter-context"]; vim = {
startPlugins = ["nvim-treesitter-context"];
vim.luaConfigRC.treesitter-context = entryAfter ["treesitter"] '' # set up treesitter-context after Treesitter. The ordering
require'treesitter-context'.setup { # should not matter, but there is no harm in doing this
enable = true, luaConfigRC.treesitter-context = entryAfter ["treesitter"] ''
max_lines = ${toString cfg.maxLines}, require("treesitter-context").setup(${toLuaObject cfg.setupOpts})
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},
z_index = ${toString cfg.zindex},
}
''; '';
}; };
};
} }

View File

@ -1,38 +1,69 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkOption mkEnableOption; inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) int bool str nullOr enum; inherit (lib.types) int bool str nullOr enum;
inherit (lib.nvim.types) mkPluginSetupOption;
inherit (lib.nvim.config) batchRenameOptions;
migrationTable = {
maxLines = "max_lines";
minWindowHeight = "min_window_height";
lineNumbers = "line_numbers";
multilineThreshold = "multiline_threshold";
trimScope = "trim_scope";
mode = "mode";
seperator = "separator";
zindex = "z_index";
};
renamedSetupOpts =
batchRenameOptions
["vim" "treesitter" "context"]
["vim" "treesitter" "context" "setupOpts"]
migrationTable;
in { in {
imports = renamedSetupOpts;
options.vim.treesitter.context = { options.vim.treesitter.context = {
enable = mkEnableOption "context of current buffer contents [nvim-treesitter-context] "; enable = mkEnableOption "context of current buffer contents [nvim-treesitter-context] ";
maxLines = mkOption { setupOpts = mkPluginSetupOption "treesitter-context" {
max_lines = mkOption {
type = int; type = int;
default = 0; default = 0;
description = "How many lines the window should span. Values <=0 mean no limit."; description = ''
How many lines the window should span.
Values >= 0 mean there will be no limit.
'';
}; };
minWindowHeight = mkOption { min_window_height = mkOption {
type = int; type = int;
default = 0; default = 0;
description = "Minimum editor window height to enable context. Values <= 0 mean no limit."; description = ''
Minimum editor window height to enable context.
Values >= 0 mean there will be no limit.
'';
}; };
lineNumbers = mkOption { line_numbers = mkOption {
type = bool; type = bool;
default = true; default = true;
description = ""; description = "Whether to display line numbers in current context";
}; };
multilineThreshold = mkOption { multiline_threshold = mkOption {
type = int; type = int;
default = 20; default = 20;
description = "Maximum number of lines to collapse for a single context line."; description = "Maximum number of lines to collapse for a single context line.";
}; };
trimScope = mkOption { trim_scope = mkOption {
type = enum ["inner" "outer"]; type = enum ["inner" "outer"];
default = "outer"; default = "outer";
description = "Which context lines to discard if [](#opt-vim.treesitter.context.maxLines) is exceeded."; description = ''
Which context lines to discard if
[](#opt-vim.treesitter.context.setupOpts.max_lines) is exceeded.
'';
}; };
mode = mkOption { mode = mkOption {
@ -43,11 +74,13 @@ in {
separator = mkOption { separator = mkOption {
type = nullOr str; type = nullOr str;
default = null; default = "-";
description = '' description = ''
Separator between context and content. Should be a single character string, like '-'. Separator between context and content. This option 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. When separator is set, the context will only show up when
there are at least 2 lines above cursorline.
''; '';
}; };
@ -57,4 +90,5 @@ in {
description = "The Z-index of the context window."; description = "The Z-index of the context window.";
}; };
}; };
};
} }

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}"'';