Skip to content
This repository was archived by the owner on Aug 10, 2023. It is now read-only.

Commit ea2500a

Browse files
committed
Treesitter (context): Update and add options
Repository is now owned by "nvim-treesitter" Update tracking issue: jordanisaacs#33
1 parent 738a370 commit ea2500a

File tree

3 files changed

+72
-18
lines changed

3 files changed

+72
-18
lines changed

flake.lock

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
flake = false;
2828
};
2929
nvim-treesitter-context = {
30-
url = "github:lewis6991/nvim-treesitter-context";
30+
url = "github:nvim-treesitter/nvim-treesitter-context";
3131
flake = false;
3232
};
3333
nvim-lightbulb = {

modules/treesitter/context.nix

+66-12
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,79 @@
66
}:
77
with lib;
88
with builtins; let
9-
cfg = config.vim.treesitter;
9+
treesitter = config.vim.treesitter;
10+
cfg = treesitter.context;
1011
in {
11-
options.vim.treesitter.context.enable = mkOption {
12-
type = types.bool;
13-
default = false;
14-
description = "enable function context [nvim-treesitter-context]";
12+
options.vim.treesitter.context = {
13+
enable = mkEnableOption "context of current buffer contents [nvim-treesitter-context] ";
14+
15+
maxLines = mkOption {
16+
description = "How many lines the window should span. Values <= 0 mean no limit.";
17+
type = types.int;
18+
default = 0;
19+
};
20+
21+
minWindowHeight = mkOption {
22+
description = "Minimum editor window height to enable context. Values <= 0 mean no limit.";
23+
type = types.int;
24+
default = 0;
25+
};
26+
27+
lineNumbers = mkOption {
28+
description = "";
29+
type = types.bool;
30+
default = true;
31+
};
32+
33+
multilineThreshold = mkOption {
34+
description = "Maximum number of lines to collapse for a single context line.";
35+
type = types.int;
36+
default = 20;
37+
};
38+
39+
trimScope = mkOption {
40+
description = nvim.nmd.asciiDoc "Which context lines to discard if <<opt-vim.treesitter.context.maxLines>> is exceeded.";
41+
type = types.enum ["inner" "outer"];
42+
default = "outer";
43+
};
44+
45+
mode = mkOption {
46+
description = "Line used to calculate context.";
47+
type = types.enum ["cursor" "topline"];
48+
default = "cursor";
49+
};
50+
51+
separator = mkOption {
52+
description = nvim.nmd.asciiDoc ''
53+
Separator between context and content. Should be a single character string, like '-'.
54+
55+
When separator is set, the context will only show up when there are at least 2 lines above cursorline.
56+
'';
57+
type = with types; nullOr str;
58+
default = null;
59+
};
60+
61+
zindex = mkOption {
62+
description = "The Z-index of the context window.";
63+
type = types.int;
64+
default = 20;
65+
};
1566
};
1667

17-
config = mkIf (cfg.enable && cfg.context.enable) {
18-
vim.startPlugins = [
19-
"nvim-treesitter-context"
20-
];
68+
config = mkIf (treesitter.enable && cfg.enable) {
69+
vim.startPlugins = ["nvim-treesitter-context"];
2170

2271
vim.luaConfigRC.treesitter-context = nvim.dag.entryAnywhere ''
23-
-- Treesitter Context config
2472
require'treesitter-context'.setup {
2573
enable = true,
26-
throttle = true,
27-
max_lines = 0
74+
max_lines = ${toString cfg.maxLines},
75+
min_window_height = ${toString cfg.minWindowHeight},
76+
line_numbers = ${boolToString cfg.lineNumbers},
77+
multiline_threshold = ${toString cfg.multilineThreshold},
78+
trim_scope = '${cfg.trimScope}',
79+
mode = '${cfg.mode}',
80+
separator = ${nvim.lua.nullString cfg.separator},
81+
max_lines = ${toString cfg.zindex},
2882
}
2983
'';
3084
};

0 commit comments

Comments
 (0)