plugins/treesitter-context: switch to mkNeovimPlugin

This commit is contained in:
Gaetan Lepage 2024-04-22 09:55:02 +02:00 committed by Gaétan Lepage
parent c1ae78cd8c
commit 6ebd538ede
2 changed files with 57 additions and 49 deletions

View file

@ -5,34 +5,51 @@
pkgs, pkgs,
... ...
}: }:
with lib; let with lib;
cfg = config.plugins.treesitter-context; helpers.neovim-plugin.mkNeovimPlugin config {
in { name = "treesitter-context";
options.plugins.treesitter-context = originalName = "nvim-treesitter-context";
helpers.neovim-plugin.extraOptionsOptions defaultPackage = pkgs.vimPlugins.nvim-treesitter-context;
// {
enable = mkEnableOption "nvim-treesitter-context";
package = helpers.mkPackageOption "nvim-treesitter-context" pkgs.vimPlugins.nvim-treesitter-context; maintainers = [maintainers.GaetanLepage];
maxLines = helpers.defaultNullOpts.mkUnsignedInt 0 '' # TODO introduced 2024-04-22: remove 2024-06-22
deprecateExtraOptions = true;
optionsRenamedToSettings = [
"maxLines"
"minWindowHeight"
"lineNumbers"
"multilineThreshold"
"trimScope"
"mode"
"separator"
"zindex"
"onAttach"
];
settingsOptions = {
enable = helpers.defaultNullOpts.mkBool true ''
Enable this plugin (Can be enabled/disabled later via commands)
'';
max_lines = helpers.defaultNullOpts.mkUnsignedInt 0 ''
How many lines the window should span. 0 means no limit. How many lines the window should span. 0 means no limit.
''; '';
minWindowHeight = helpers.defaultNullOpts.mkUnsignedInt 0 '' min_window_height = helpers.defaultNullOpts.mkUnsignedInt 0 ''
Minimum editor window height to enable context. 0 means no limit. Minimum editor window height to enable context. 0 means no limit.
''; '';
lineNumbers = helpers.defaultNullOpts.mkBool true '' line_numbers = helpers.defaultNullOpts.mkBool true ''
Whether to show line numbers. Whether to show line numbers.
''; '';
multilineThreshold = helpers.defaultNullOpts.mkUnsignedInt 20 '' multiline_threshold = helpers.defaultNullOpts.mkUnsignedInt 20 ''
Maximum number of lines to collapse for a single context line. Maximum number of lines to collapse for a single context line.
''; '';
trimScope = helpers.defaultNullOpts.mkEnumFirstDefault ["outer" "inner"] '' trim_scope = helpers.defaultNullOpts.mkEnumFirstDefault ["outer" "inner"] ''
Which context lines to discard if `maxLines` is exceeded. Which context lines to discard if `max_lines` is exceeded.
''; '';
mode = helpers.defaultNullOpts.mkEnumFirstDefault ["cursor" "topline"] '' mode = helpers.defaultNullOpts.mkEnumFirstDefault ["cursor" "topline"] ''
@ -50,39 +67,27 @@ in {
The Z-index of the context window. The Z-index of the context window.
''; '';
onAttach = helpers.defaultNullOpts.mkLuaFn "nil" '' on_attach = helpers.defaultNullOpts.mkLuaFn "nil" ''
The implementation of a lua function which takes an integer `buf` as parameter and returns a The implementation of a lua function which takes an integer `buf` as parameter and returns a
boolean. boolean.
Return `false` to disable attaching. Return `false` to disable attaching.
''; '';
}; };
config = let settingsExample = {
setupOptions = with cfg; max_lines = 0;
{ min_window_height = 0;
max_lines = maxLines; line_numbers = true;
min_window_height = minWindowHeight; multiline_threshold = 20;
line_numbers = lineNumbers; trim_scope = "inner";
multiline_threshold = multilineThreshold; mode = "topline";
trim_scope = trimScope; separator = "-";
inherit zindex = 20;
mode };
separator
zindex extraConfig = cfg: {
;
on_attach = onAttach;
}
// cfg.extraOptions;
in
mkIf cfg.enable {
warnings = mkIf (!config.plugins.treesitter.enable) [ warnings = mkIf (!config.plugins.treesitter.enable) [
"Nixvim: treesitter-context needs treesitter to function as intended" "Nixvim: treesitter-context needs treesitter to function as intended"
]; ];
extraPlugins = [cfg.package];
extraConfigLua = ''
require('treesitter-context').setup(${helpers.toLuaObject setupOptions})
'';
}; };
} }

View file

@ -12,15 +12,18 @@
treesitter-context = { treesitter-context = {
enable = true; enable = true;
maxLines = 0; settings = {
minWindowHeight = 0; enable = true;
lineNumbers = true; max_lines = 0;
multilineThreshold = 20; min_window_height = 0;
trimScope = "outer"; line_numbers = true;
mode = "cursor"; multiline_threshold = 20;
separator = null; trim_scope = "outer";
zindex = 20; mode = "cursor";
onAttach = null; separator = null;
zindex = 20;
on_attach = null;
};
}; };
}; };
}; };