plugins/treesitter-context: reflect upstream options changes

This commit is contained in:
Gaetan Lepage 2023-08-25 15:09:44 +02:00 committed by Gaétan Lepage
parent d0cbfe92b3
commit b8c3385599
2 changed files with 105 additions and 36 deletions

View file

@ -5,48 +5,92 @@
... ...
}: }:
with lib; let with lib; let
cfg = config.plugins.treesitter-context;
helpers = import ../../helpers.nix {inherit lib;}; helpers = import ../../helpers.nix {inherit lib;};
in { in {
options.plugins.treesitter-context = { # Those warnings were introduced on 08/25/2023. TODO: remove them in October 2023.
enable = mkEnableOption "nvim-treesitter-context"; imports = let
basePluginPath = ["plugins" "treesitter-context"];
in [
(
mkRenamedOptionModule
(basePluginPath ++ ["maxWindowHeight"])
(basePluginPath ++ ["minWindowHeight"])
)
(
mkRemovedOptionModule (basePluginPath ++ ["patterns"]) ""
)
(
mkRemovedOptionModule (basePluginPath ++ ["extractPatterns"]) ""
)
];
options.plugins.treesitter-context =
helpers.extraOptionsOptions
// {
enable = mkEnableOption "nvim-treesitter-context";
package = helpers.mkPackageOption "treesitter-context" pkgs.vimPlugins.nvim-treesitter-context; package = helpers.mkPackageOption "nvim-treesitter-context" pkgs.vimPlugins.nvim-treesitter-context;
maxLines = mkOption { maxLines = helpers.defaultNullOpts.mkUnsignedInt 0 ''
type = types.nullOr types.ints.positive; How many lines the window should span. 0 means no limit.
default = null; '';
description = "How many lines the window should span. Null means no limit";
};
trimScope = mkOption { minWindowHeight = helpers.defaultNullOpts.mkUnsignedInt 0 ''
type = types.enum ["outer" "inner"]; Minimum editor window height to enable context. 0 means no limit.
default = "outer"; '';
description = "Which context lines to discard if `max_lines` is exceeded";
};
maxWindowHeight = mkOption { lineNumbers = helpers.defaultNullOpts.mkBool true ''
type = types.nullOr types.ints.positive; Whether to show line numbers.
default = null; '';
description = "Minimum editor window height to enable context";
};
patterns = mkOption { multilineThreshold = helpers.defaultNullOpts.mkUnsignedInt 20 ''
type = types.attrsOf (types.listOf types.str); Maximum number of lines to collapse for a single context line.
default = {}; '';
description = ''
Patterns to use for context delimitation. The 'default' key matches all filetypes trimScope = helpers.defaultNullOpts.mkEnumFirstDefault ["outer" "inner"] ''
Which context lines to discard if `maxLines` is exceeded.
'';
mode = helpers.defaultNullOpts.mkEnumFirstDefault ["cursor" "topline"] ''
Line used to calculate context.
'';
separator = helpers.mkNullOrOption types.str ''
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.
'';
zindex = helpers.defaultNullOpts.mkUnsignedInt 20 ''
The Z-index of the context window.
'';
onAttach = helpers.mkNullOrOption types.str ''
The implementation of a lua function which takes an integer `buf` as parameter and returns a
boolean.
Return `false` to disable attaching.
''; '';
}; };
exactPatterns = mkOption {
type = types.attrsOf types.bool;
default = {};
description = "Treat the coresponding entry in patterns as an exact match";
};
};
config = let config = let
cfg = config.plugins.treesitter-context; setupOptions = with cfg;
{
max_lines = maxLines;
min_window_height = minWindowHeight;
line_numbers = lineNumbers;
multiline_threshold = multilineThreshold;
trim_scope = trimScope;
inherit
mode
separator
zindex
;
on_attach =
helpers.ifNonNull' onAttach
(helpers.mkRaw onAttach);
}
// cfg.extraOptions;
in in
mkIf cfg.enable { mkIf cfg.enable {
warnings = mkIf (!config.plugins.treesitter.enable) [ warnings = mkIf (!config.plugins.treesitter.enable) [
@ -55,10 +99,8 @@ in {
extraPlugins = [cfg.package]; extraPlugins = [cfg.package];
plugins.treesitter.moduleConfig.context = { extraConfigLua = ''
max_lines = cfg.maxLines; require('treesitter-context').setup(${helpers.toLuaObject setupOptions})
trim_scope = cfg.trimScope; '';
min_window_height = cfg.maxWindowHeight;
};
}; };
} }

View file

@ -0,0 +1,27 @@
{pkgs}: {
empty = {
plugins = {
treesitter.enable = true;
treesitter-context.enable = true;
};
};
default = {
plugins = {
treesitter.enable = true;
treesitter-context = {
enable = true;
maxLines = 0;
minWindowHeight = 0;
lineNumbers = true;
multilineThreshold = 20;
trimScope = "outer";
mode = "cursor";
separator = null;
zindex = 20;
onAttach = null;
};
};
};
}