2023-02-20 11:42:13 +01:00
|
|
|
{
|
|
|
|
lib,
|
2023-11-06 15:04:08 +01:00
|
|
|
helpers,
|
2023-02-20 11:42:13 +01:00
|
|
|
config,
|
2023-11-06 15:04:08 +01:00
|
|
|
pkgs,
|
2023-02-20 11:42:13 +01:00
|
|
|
...
|
2023-01-06 12:31:54 +01:00
|
|
|
}:
|
2023-02-20 11:42:13 +01:00
|
|
|
with lib; let
|
2023-08-25 15:09:44 +02:00
|
|
|
cfg = config.plugins.treesitter-context;
|
2023-01-25 19:46:49 +01:00
|
|
|
in {
|
2023-08-25 15:09:44 +02:00
|
|
|
options.plugins.treesitter-context =
|
|
|
|
helpers.extraOptionsOptions
|
|
|
|
// {
|
|
|
|
enable = mkEnableOption "nvim-treesitter-context";
|
2023-01-06 12:31:54 +01:00
|
|
|
|
2023-08-25 15:09:44 +02:00
|
|
|
package = helpers.mkPackageOption "nvim-treesitter-context" pkgs.vimPlugins.nvim-treesitter-context;
|
2023-01-19 10:45:15 +00:00
|
|
|
|
2023-08-25 15:09:44 +02:00
|
|
|
maxLines = helpers.defaultNullOpts.mkUnsignedInt 0 ''
|
|
|
|
How many lines the window should span. 0 means no limit.
|
|
|
|
'';
|
2023-01-06 12:31:54 +01:00
|
|
|
|
2023-08-25 15:09:44 +02:00
|
|
|
minWindowHeight = helpers.defaultNullOpts.mkUnsignedInt 0 ''
|
|
|
|
Minimum editor window height to enable context. 0 means no limit.
|
|
|
|
'';
|
2023-01-06 12:31:54 +01:00
|
|
|
|
2023-08-25 15:09:44 +02:00
|
|
|
lineNumbers = helpers.defaultNullOpts.mkBool true ''
|
|
|
|
Whether to show line numbers.
|
|
|
|
'';
|
2023-01-06 12:31:54 +01:00
|
|
|
|
2023-08-25 15:09:44 +02:00
|
|
|
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.
|
2023-01-06 12:31:54 +01:00
|
|
|
'';
|
|
|
|
|
2023-08-25 15:09:44 +02:00
|
|
|
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.
|
|
|
|
'';
|
2023-01-06 12:31:54 +01:00
|
|
|
};
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
config = let
|
2023-08-25 15:09:44 +02:00
|
|
|
setupOptions = with cfg;
|
|
|
|
{
|
|
|
|
max_lines = maxLines;
|
|
|
|
min_window_height = minWindowHeight;
|
|
|
|
line_numbers = lineNumbers;
|
|
|
|
multiline_threshold = multilineThreshold;
|
|
|
|
trim_scope = trimScope;
|
|
|
|
inherit
|
|
|
|
mode
|
|
|
|
separator
|
|
|
|
zindex
|
|
|
|
;
|
2023-11-22 12:00:32 +01:00
|
|
|
on_attach = helpers.mkRaw onAttach;
|
2023-08-25 15:09:44 +02:00
|
|
|
}
|
|
|
|
// cfg.extraOptions;
|
2023-02-20 11:42:13 +01:00
|
|
|
in
|
2023-01-06 12:31:54 +01:00
|
|
|
mkIf cfg.enable {
|
2023-06-01 10:31:23 +02:00
|
|
|
warnings = mkIf (!config.plugins.treesitter.enable) [
|
|
|
|
"Nixvim: treesitter-context needs treesitter to function as intended"
|
|
|
|
];
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
extraPlugins = [cfg.package];
|
2023-01-06 12:31:54 +01:00
|
|
|
|
2023-08-25 15:09:44 +02:00
|
|
|
extraConfigLua = ''
|
|
|
|
require('treesitter-context').setup(${helpers.toLuaObject setupOptions})
|
|
|
|
'';
|
2023-01-06 12:31:54 +01:00
|
|
|
};
|
|
|
|
}
|