Skip to content

Commit

Permalink
plugins/treesitter-context: reflect upstream options changes
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Aug 25, 2023
1 parent d0cbfe9 commit b8c3385
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 35 deletions.
112 changes: 77 additions & 35 deletions plugins/languages/treesitter/treesitter-context.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,92 @@
...
}:
with lib; let
cfg = config.plugins.treesitter-context;
helpers = import ../../helpers.nix {inherit lib;};
in {
options.plugins.treesitter-context = {
enable = mkEnableOption "nvim-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.
'';
};

exactPatterns = mkOption {
type = types.attrsOf types.bool;
default = {};
description = "Treat the coresponding entry in patterns as an exact match";
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.
'';
};
};

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) [
Expand All @@ -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})
'';
};
}
Original file line number Diff line number Diff line change
@@ -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;
};
};
};
}

0 comments on commit b8c3385

Please sign in to comment.