neovim-flake/modules/treesitter/context.nix

90 lines
2.5 KiB
Nix
Raw Normal View History

{
config,
lib,
...
}: let
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) int bool str nullOr enum;
inherit (lib.modules) mkIf;
inherit (lib.trivial) boolToString;
inherit (lib.nvim.lua) nullString;
inherit (lib.nvim.dag) entryAnywhere;
inherit (config.vim) treesitter;
2023-04-18 01:10:40 +02:00
cfg = treesitter.context;
in {
2023-04-18 01:10:40 +02:00
options.vim.treesitter.context = {
enable = mkEnableOption "context of current buffer contents [nvim-treesitter-context] ";
maxLines = mkOption {
description = "How many lines the window should span. Values <=0 mean no limit.";
type = int;
2023-04-18 01:10:40 +02:00
default = 0;
};
minWindowHeight = mkOption {
description = "Minimum editor window height to enable context. Values <= 0 mean no limit.";
type = int;
2023-04-18 01:10:40 +02:00
default = 0;
};
lineNumbers = mkOption {
description = "";
type = bool;
2023-04-18 01:10:40 +02:00
default = true;
};
multilineThreshold = mkOption {
description = "Maximum number of lines to collapse for a single context line.";
type = int;
2023-04-18 01:10:40 +02:00
default = 20;
};
trimScope = mkOption {
description = "Which context lines to discard if [](#opt-vim.treesitter.context.maxLines) is exceeded.";
type = enum ["inner" "outer"];
2023-04-18 01:10:40 +02:00
default = "outer";
};
mode = mkOption {
description = "Line used to calculate context.";
type = enum ["cursor" "topline"];
2023-04-18 01:10:40 +02:00
default = "cursor";
};
separator = mkOption {
description = ''
2023-04-18 01:10:40 +02:00
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.
'';
type = nullOr str;
2023-04-18 01:10:40 +02:00
default = null;
};
zindex = mkOption {
description = "The Z-index of the context window.";
type = int;
2023-04-18 01:10:40 +02:00
default = 20;
};
};
2023-04-18 01:10:40 +02:00
config = mkIf (treesitter.enable && cfg.enable) {
vim.startPlugins = ["nvim-treesitter-context"];
vim.luaConfigRC.treesitter-context = entryAnywhere ''
require'treesitter-context'.setup {
enable = true,
2023-04-18 01:10:40 +02:00
max_lines = ${toString cfg.maxLines},
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},
2023-04-18 01:10:40 +02:00
max_lines = ${toString cfg.zindex},
}
'';
};
}