mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 16:39:00 +02:00
plugins/treesitter-context: reflect upstream options changes
This commit is contained in:
parent
d0cbfe92b3
commit
b8c3385599
2 changed files with 105 additions and 36 deletions
|
@ -5,48 +5,92 @@
|
|||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.plugins.treesitter-context;
|
||||
helpers = import ../../helpers.nix {inherit lib;};
|
||||
in {
|
||||
options.plugins.treesitter-context = {
|
||||
# Those warnings were introduced on 08/25/2023. TODO: remove them in October 2023.
|
||||
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 {
|
||||
type = types.nullOr types.ints.positive;
|
||||
default = null;
|
||||
description = "How many lines the window should span. Null means no limit";
|
||||
};
|
||||
maxLines = helpers.defaultNullOpts.mkUnsignedInt 0 ''
|
||||
How many lines the window should span. 0 means no limit.
|
||||
'';
|
||||
|
||||
trimScope = mkOption {
|
||||
type = types.enum ["outer" "inner"];
|
||||
default = "outer";
|
||||
description = "Which context lines to discard if `max_lines` is exceeded";
|
||||
};
|
||||
minWindowHeight = helpers.defaultNullOpts.mkUnsignedInt 0 ''
|
||||
Minimum editor window height to enable context. 0 means no limit.
|
||||
'';
|
||||
|
||||
maxWindowHeight = mkOption {
|
||||
type = types.nullOr types.ints.positive;
|
||||
default = null;
|
||||
description = "Minimum editor window height to enable context";
|
||||
};
|
||||
lineNumbers = helpers.defaultNullOpts.mkBool true ''
|
||||
Whether to show line numbers.
|
||||
'';
|
||||
|
||||
patterns = mkOption {
|
||||
type = types.attrsOf (types.listOf types.str);
|
||||
default = {};
|
||||
description = ''
|
||||
Patterns to use for context delimitation. The 'default' key matches all filetypes
|
||||
multilineThreshold = helpers.defaultNullOpts.mkUnsignedInt 20 ''
|
||||
Maximum number of lines to collapse for a single context line.
|
||||
'';
|
||||
|
||||
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
|
||||
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
|
||||
mkIf cfg.enable {
|
||||
warnings = mkIf (!config.plugins.treesitter.enable) [
|
||||
|
@ -55,10 +99,8 @@ in {
|
|||
|
||||
extraPlugins = [cfg.package];
|
||||
|
||||
plugins.treesitter.moduleConfig.context = {
|
||||
max_lines = cfg.maxLines;
|
||||
trim_scope = cfg.trimScope;
|
||||
min_window_height = cfg.maxWindowHeight;
|
||||
};
|
||||
extraConfigLua = ''
|
||||
require('treesitter-context').setup(${helpers.toLuaObject setupOptions})
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue