mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2024-11-07 12:45:57 +01:00
plugins/treesitter: migrate treesitter-context to new setupOpts
This commit is contained in:
parent
e8035c42f4
commit
c8d38872ab
4 changed files with 94 additions and 59 deletions
|
@ -39,8 +39,13 @@ in {
|
||||||
|
|
||||||
# For some reason treesitter highlighting does not work on start if this is set before syntax on
|
# For some reason treesitter highlighting does not work on start if this is set before syntax on
|
||||||
configRC.treesitter-fold = mkIf cfg.fold (entryBefore ["basic"] ''
|
configRC.treesitter-fold = mkIf cfg.fold (entryBefore ["basic"] ''
|
||||||
|
" This is required by treesitter-context to handle folds
|
||||||
set foldmethod=expr
|
set foldmethod=expr
|
||||||
set foldexpr=nvim_treesitter#foldexpr()
|
set foldexpr=nvim_treesitter#foldexpr()
|
||||||
|
|
||||||
|
" This is optional, but is set rather as a sane default.
|
||||||
|
" If unset, opened files will be folded by automatically as
|
||||||
|
" the files are opened
|
||||||
set nofoldenable
|
set nofoldenable
|
||||||
'');
|
'');
|
||||||
|
|
||||||
|
@ -67,6 +72,9 @@ in {
|
||||||
},
|
},
|
||||||
|
|
||||||
-- Indentation module for Treesitter
|
-- Indentation module for Treesitter
|
||||||
|
-- Keymaps are set to false here as they are
|
||||||
|
-- handled by `vim.maps` entries calling lua
|
||||||
|
-- functions achieving the same functionality.
|
||||||
incremental_selection = {
|
incremental_selection = {
|
||||||
enable = true,
|
enable = true,
|
||||||
disable = {},
|
disable = {},
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
inherit (lib.options) mkOption mkEnableOption literalMD;
|
inherit (lib.options) mkOption mkEnableOption literalMD;
|
||||||
inherit (lib.types) listOf package str either bool;
|
inherit (lib.types) listOf package str either bool;
|
||||||
inherit (lib.nvim.binds) mkMappingOption;
|
inherit (lib.nvim.binds) mkMappingOption;
|
||||||
inherit (lib.nvim.types) luaInline mkGrammarOption;
|
inherit (lib.nvim.types) luaInline;
|
||||||
in {
|
in {
|
||||||
options.vim.treesitter = {
|
options.vim.treesitter = {
|
||||||
enable = mkEnableOption "treesitter, also enabled automatically through language options";
|
enable = mkEnableOption "treesitter, also enabled automatically through language options";
|
||||||
|
|
|
@ -4,28 +4,21 @@
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.modules) mkIf;
|
inherit (lib.modules) mkIf;
|
||||||
inherit (lib.trivial) boolToString;
|
inherit (lib.nvim.lua) toLuaObject;
|
||||||
inherit (lib.nvim.lua) nullString;
|
|
||||||
inherit (lib.nvim.dag) entryAfter;
|
inherit (lib.nvim.dag) entryAfter;
|
||||||
|
|
||||||
inherit (config.vim) treesitter;
|
inherit (config.vim) treesitter;
|
||||||
cfg = treesitter.context;
|
cfg = treesitter.context;
|
||||||
in {
|
in {
|
||||||
config = mkIf (treesitter.enable && cfg.enable) {
|
config = mkIf (treesitter.enable && cfg.enable) {
|
||||||
vim.startPlugins = ["nvim-treesitter-context"];
|
vim = {
|
||||||
|
startPlugins = ["nvim-treesitter-context"];
|
||||||
|
|
||||||
vim.luaConfigRC.treesitter-context = entryAfter ["treesitter"] ''
|
# set up treesitter-context after Treesitter. The ordering
|
||||||
require'treesitter-context'.setup {
|
# should not matter, but there is no harm in doing this
|
||||||
enable = true,
|
luaConfigRC.treesitter-context = entryAfter ["treesitter"] ''
|
||||||
max_lines = ${toString cfg.maxLines},
|
require("treesitter-context").setup(${toLuaObject cfg.setupOpts})
|
||||||
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},
|
|
||||||
z_index = ${toString cfg.zindex},
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,60 +1,94 @@
|
||||||
{lib, ...}: let
|
{lib, ...}: let
|
||||||
inherit (lib.options) mkOption mkEnableOption;
|
inherit (lib.options) mkOption mkEnableOption;
|
||||||
inherit (lib.types) int bool str nullOr enum;
|
inherit (lib.types) int bool str nullOr enum;
|
||||||
|
inherit (lib.nvim.types) mkPluginSetupOption;
|
||||||
|
inherit (lib.nvim.config) batchRenameOptions;
|
||||||
|
migrationTable = {
|
||||||
|
maxLines = "max_lines";
|
||||||
|
minWindowHeight = "min_window_height";
|
||||||
|
lineNumbers = "line_numbers";
|
||||||
|
multilineThreshold = "multiline_threshold";
|
||||||
|
trimScope = "trim_scope";
|
||||||
|
mode = "mode";
|
||||||
|
seperator = "separator";
|
||||||
|
zindex = "z_index";
|
||||||
|
};
|
||||||
|
|
||||||
|
renamedSetupOpts =
|
||||||
|
batchRenameOptions
|
||||||
|
["vim" "treesitter" "context"]
|
||||||
|
["vim" "treesitter" "context" "setupOpts"]
|
||||||
|
migrationTable;
|
||||||
in {
|
in {
|
||||||
|
imports = renamedSetupOpts;
|
||||||
options.vim.treesitter.context = {
|
options.vim.treesitter.context = {
|
||||||
enable = mkEnableOption "context of current buffer contents [nvim-treesitter-context] ";
|
enable = mkEnableOption "context of current buffer contents [nvim-treesitter-context] ";
|
||||||
|
|
||||||
maxLines = mkOption {
|
setupOpts = mkPluginSetupOption "treesitter-context" {
|
||||||
type = int;
|
max_lines = mkOption {
|
||||||
default = 0;
|
type = int;
|
||||||
description = "How many lines the window should span. Values <=0 mean no limit.";
|
default = 0;
|
||||||
};
|
description = ''
|
||||||
|
How many lines the window should span.
|
||||||
|
|
||||||
minWindowHeight = mkOption {
|
Values >= 0 mean there will be no limit.
|
||||||
type = int;
|
'';
|
||||||
default = 0;
|
};
|
||||||
description = "Minimum editor window height to enable context. Values <= 0 mean no limit.";
|
|
||||||
};
|
|
||||||
|
|
||||||
lineNumbers = mkOption {
|
min_window_height = mkOption {
|
||||||
type = bool;
|
type = int;
|
||||||
default = true;
|
default = 0;
|
||||||
description = "";
|
description = ''
|
||||||
};
|
Minimum editor window height to enable context.
|
||||||
|
|
||||||
multilineThreshold = mkOption {
|
Values >= 0 mean there will be no limit.
|
||||||
type = int;
|
'';
|
||||||
default = 20;
|
};
|
||||||
description = "Maximum number of lines to collapse for a single context line.";
|
|
||||||
};
|
|
||||||
|
|
||||||
trimScope = mkOption {
|
line_numbers = mkOption {
|
||||||
type = enum ["inner" "outer"];
|
type = bool;
|
||||||
default = "outer";
|
default = true;
|
||||||
description = "Which context lines to discard if [](#opt-vim.treesitter.context.maxLines) is exceeded.";
|
description = "Whether to display line numbers in current context";
|
||||||
};
|
};
|
||||||
|
|
||||||
mode = mkOption {
|
multiline_threshold = mkOption {
|
||||||
type = enum ["cursor" "topline"];
|
type = int;
|
||||||
default = "cursor";
|
default = 20;
|
||||||
description = "Line used to calculate context.";
|
description = "Maximum number of lines to collapse for a single context line.";
|
||||||
};
|
};
|
||||||
|
|
||||||
separator = mkOption {
|
trim_scope = mkOption {
|
||||||
type = nullOr str;
|
type = enum ["inner" "outer"];
|
||||||
default = null;
|
default = "outer";
|
||||||
description = ''
|
description = ''
|
||||||
Separator between context and content. Should be a single character string, like '-'.
|
Which context lines to discard if
|
||||||
|
[](#opt-vim.treesitter.context.setupOpts.max_lines) is exceeded.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
When separator is set, the context will only show up when there are at least 2 lines above cursorline.
|
mode = mkOption {
|
||||||
'';
|
type = enum ["cursor" "topline"];
|
||||||
};
|
default = "cursor";
|
||||||
|
description = "Line used to calculate context.";
|
||||||
|
};
|
||||||
|
|
||||||
zindex = mkOption {
|
separator = mkOption {
|
||||||
type = int;
|
type = nullOr str;
|
||||||
default = 20;
|
default = "-";
|
||||||
description = "The Z-index of the context window.";
|
description = ''
|
||||||
|
Separator between context and content. This option 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 = mkOption {
|
||||||
|
type = int;
|
||||||
|
default = 20;
|
||||||
|
description = "The Z-index of the context window.";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue