mirror of
https://github.com/NotAShelf/nvf.git
synced 2024-11-26 15:06:45 +00:00
Merge pull request #261 from NotAShelf/treesitter
plugins/treesitter: migrate legacy codebase; refactor
This commit is contained in:
commit
bba0ba92a6
13 changed files with 462 additions and 202 deletions
60
flake.lock
60
flake.lock
|
@ -131,11 +131,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1713714899,
|
||||
"narHash": "sha256-+z/XjO3QJs5rLE5UOf015gdVauVRQd2vZtsFkaXBq2Y=",
|
||||
"lastModified": 1713895582,
|
||||
"narHash": "sha256-cfh1hi+6muQMbi9acOlju3V1gl8BEaZBXBR9jQfQi4U=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "6143fc5eeb9c4f00163267708e26191d1e918932",
|
||||
"rev": "572af610f6151fd41c212f897c71f7056e3fb518",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -502,11 +502,11 @@
|
|||
"plugin-crates-nvim": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1713017448,
|
||||
"narHash": "sha256-rRm7xXt5+u76ylWhLYXwjDqxWQL8epfjnTHLv7M+Lc8=",
|
||||
"lastModified": 1713995074,
|
||||
"narHash": "sha256-09+mBhh5hAXENPzrvwNNQEyM7ZtuPYAWrtAG/pzBOV8=",
|
||||
"owner": "Saecki",
|
||||
"repo": "crates.nvim",
|
||||
"rev": "786d12a70c9b91fa2d0d102bb07df02be0db31a1",
|
||||
"rev": "f00e11e8282b94f2a2e938d32712c99f0e0bdeb4",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -566,11 +566,11 @@
|
|||
"plugin-dressing-nvim": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1710299803,
|
||||
"narHash": "sha256-9AwOFTRvhWFo7USgoFYfceiojZM62IXPpBs8CnSqc18=",
|
||||
"lastModified": 1713925216,
|
||||
"narHash": "sha256-46r7X8CNuMgSB9X1jFLTQAiiBVqszkBP6DPlo6nBAxI=",
|
||||
"owner": "stevearc",
|
||||
"repo": "dressing.nvim",
|
||||
"rev": "18e5beb3845f085b6a33c24112b37988f3f93c06",
|
||||
"rev": "5162edb1442a729a885c45455a07e9a89058be2f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -646,11 +646,11 @@
|
|||
"plugin-gesture-nvim": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1713827672,
|
||||
"narHash": "sha256-YsE4mqM5hBsv4uaCYEpqcA6ZhVKgWWQ4/oHVVdX+vnA=",
|
||||
"lastModified": 1713872849,
|
||||
"narHash": "sha256-npryXJ92l65gOGltTd3jE3fdhiEgqbxCdK5w/C/BQV0=",
|
||||
"owner": "notomo",
|
||||
"repo": "gesture.nvim",
|
||||
"rev": "547f9b50b87e2ec40e72465fc2f975bb6b6232ff",
|
||||
"rev": "47175ed2741ba46fe7f14d6ee37ebbc5b9614c5a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -758,11 +758,11 @@
|
|||
"plugin-image-nvim": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1713467683,
|
||||
"narHash": "sha256-qSGtiBl94RJMffoxXEV74fNcmrYcKtfPc3Aw65tzuDM=",
|
||||
"lastModified": 1713989303,
|
||||
"narHash": "sha256-UBrusfIYWURI1Auo3XayswA8NXgZhqwazg6wmmgWygA=",
|
||||
"owner": "3rd",
|
||||
"repo": "image.nvim",
|
||||
"rev": "301de7919b2c0378cb7a782663f67abbcb198b17",
|
||||
"rev": "2d4b479c59fd70cc26f63d48b5cd76a44dda8873",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -934,11 +934,11 @@
|
|||
"plugin-neocord": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1713646638,
|
||||
"narHash": "sha256-lcARsc0JxnzYbucRP0pY/bRMsSfm4P4Cpc5A6EoY3Lc=",
|
||||
"lastModified": 1713923379,
|
||||
"narHash": "sha256-oVWdnQlgXIMzMiybMq7yR/WfEW+Fm5RmhWx0RWprlfQ=",
|
||||
"owner": "IogaMaster",
|
||||
"repo": "neocord",
|
||||
"rev": "014e78cff9f1fc7b3b46ec67fdca68a91a9b7c65",
|
||||
"rev": "aa7a58023166533da83ca7b11c0d2569e45d7381",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -1175,11 +1175,11 @@
|
|||
"plugin-nvim-lspconfig": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1713863504,
|
||||
"narHash": "sha256-q82z4V3718/XvrCB9zRL5VwMFgkt3KS5olICSV0UUHo=",
|
||||
"lastModified": 1713908193,
|
||||
"narHash": "sha256-VdIoInJj2u49WHN4+WX0kNHdbXgh0AqIPU+OAiUaBck=",
|
||||
"owner": "neovim",
|
||||
"repo": "nvim-lspconfig",
|
||||
"rev": "ee3d635692451bc3ef0e5d4b30ea2fbfdeefc373",
|
||||
"rev": "cfa386fc4027e847156ee16141ea1f4c0bc2f0a4",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -1303,11 +1303,11 @@
|
|||
"plugin-nvim-tree-lua": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1713668329,
|
||||
"narHash": "sha256-QEvHQcEAGkm5UKVLc1DYvEqs5/JFNrkEFKHFZpe5ZDE=",
|
||||
"lastModified": 1713946472,
|
||||
"narHash": "sha256-iD8c/dXt/UcTYDK8/zkTkFW/1Ial8ulCUWojjyXpG8k=",
|
||||
"owner": "nvim-tree",
|
||||
"repo": "nvim-tree.lua",
|
||||
"rev": "ae8e46e8fabb32fa3ae5319383ea2c8763f14caa",
|
||||
"rev": "62008e5cf2e8745c9d23bb599ef642963131057e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -1319,11 +1319,11 @@
|
|||
"plugin-nvim-treesitter-context": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1713520917,
|
||||
"narHash": "sha256-AT49dDlwPaV41O+rcUCzzdra8moIg4iDAIhZJb6j0zE=",
|
||||
"lastModified": 1713984790,
|
||||
"narHash": "sha256-QAudKglQGDRJKrsEcMSjbrxTgQRXO60ZcfOvEnPLUoE=",
|
||||
"owner": "nvim-treesitter",
|
||||
"repo": "nvim-treesitter-context",
|
||||
"rev": "ba4289ad345ececd335a9cdd7b9616fd0bb6be92",
|
||||
"rev": "4fe0a54e86859744968e1a5c7867b49c86855774",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -2111,11 +2111,11 @@
|
|||
"nixpkgs": "nixpkgs_4"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1713745451,
|
||||
"narHash": "sha256-j5/bimg/wI14yTDUXZcSQRosV1LIOYuxYkZjvVJC/yg=",
|
||||
"lastModified": 1713960597,
|
||||
"narHash": "sha256-WAryNIrMfZ48iZSTh8hcHIX9vwh78LMFUtewgY7kp1Y=",
|
||||
"owner": "mitchellh",
|
||||
"repo": "zig-overlay",
|
||||
"rev": "2c86c36e7fe65faac08bdf85d041cf7b798f8ee8",
|
||||
"rev": "71894accd2dd096f5a84166a628b1f075311aafe",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
binds = import ./binds.nix {inherit lib;};
|
||||
dag = import ./dag.nix {inherit lib;};
|
||||
languages = import ./languages.nix {inherit lib;};
|
||||
lists = import ./lists.nix {inherit lib;};
|
||||
lua = import ./lua.nix {inherit lib;};
|
||||
vim = import ./vim.nix;
|
||||
}
|
||||
|
|
34
lib/lists.nix
Normal file
34
lib/lists.nix
Normal file
|
@ -0,0 +1,34 @@
|
|||
{lib}: let
|
||||
inherit (lib.lists) elem all;
|
||||
in {
|
||||
/*
|
||||
Checks if all values are present in the list.
|
||||
|
||||
Type:
|
||||
listContainsValues :: { list :: [a], values :: [a] } -> Bool
|
||||
|
||||
Arguments:
|
||||
list - A list of elements.
|
||||
values - A list of values to check for presence in the list.
|
||||
|
||||
Returns:
|
||||
True if all values are present in the list, otherwise False.
|
||||
|
||||
Example:
|
||||
```nix
|
||||
listContainsValues { list = [1 2 3]; values = [2 3]; }
|
||||
=> True
|
||||
|
||||
listContainsValues { list = [1 2 3]; values = [2 4]; }
|
||||
=> False
|
||||
```
|
||||
*/
|
||||
listContainsValues = {
|
||||
list,
|
||||
values,
|
||||
}: let
|
||||
# Check if all values are present in the list
|
||||
containsValue = value: elem value list;
|
||||
in
|
||||
all containsValue values;
|
||||
}
|
|
@ -49,7 +49,7 @@ in {
|
|||
|
||||
syntaxHighlighting = mkOption {
|
||||
type = bool;
|
||||
default = true;
|
||||
default = !config.vim.treesitter.highlight.enable;
|
||||
description = "Enable syntax highlighting";
|
||||
};
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
gitsigns = true,
|
||||
telescope = true,
|
||||
treesitter = true,
|
||||
treesitter_context = true,
|
||||
ts_rainbow = true,
|
||||
fidget = true,
|
||||
alpha = true,
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.lists) optional;
|
||||
inherit (lib.lists) optional optionals;
|
||||
inherit (lib.trivial) boolToString;
|
||||
inherit (lib.nvim.binds) mkSetBinding addDescriptionsToMappings;
|
||||
inherit (lib.nvim.dag) entryBefore entryAnywhere;
|
||||
inherit (lib.nvim.lua) toLuaObject;
|
||||
inherit (lib.nvim.dag) entryBefore entryAfter;
|
||||
|
||||
cfg = config.vim.treesitter;
|
||||
usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp";
|
||||
|
||||
self = import ./treesitter.nix {inherit lib;};
|
||||
self = import ./treesitter.nix {inherit pkgs lib;};
|
||||
mappingDefinitions = self.options.vim.treesitter.mappings;
|
||||
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions;
|
||||
in {
|
||||
|
@ -20,6 +23,7 @@ in {
|
|||
startPlugins = ["nvim-treesitter"] ++ optional usingNvimCmp "cmp-treesitter";
|
||||
|
||||
autocomplete.sources = {"treesitter" = "[Treesitter]";};
|
||||
treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars;
|
||||
|
||||
maps = {
|
||||
# HACK: Using mkSetLuaBinding and putting the lua code does not work for some reason: It just selects the whole file.
|
||||
|
@ -35,28 +39,51 @@ in {
|
|||
|
||||
# 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"] ''
|
||||
" This is required by treesitter-context to handle folds
|
||||
set foldmethod=expr
|
||||
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
|
||||
'');
|
||||
|
||||
luaConfigRC.treesitter = entryAnywhere ''
|
||||
require'nvim-treesitter.configs'.setup {
|
||||
highlight = {
|
||||
enable = true,
|
||||
disable = {},
|
||||
},
|
||||
|
||||
luaConfigRC.treesitter = entryAfter ["basic"] ''
|
||||
require('nvim-treesitter.configs').setup {
|
||||
-- Disable imperative treesitter options that would attempt to fetch
|
||||
-- grammars into the read-only Nix store. To add additional grammars here
|
||||
-- you must use the `config.vim.treesitter.grammars` option.
|
||||
auto_install = false,
|
||||
sync_install = false,
|
||||
ensure_installed = {},
|
||||
|
||||
-- Indentation module for Treesitter
|
||||
indent = {
|
||||
enable = ${toLuaObject cfg.indent.enable},
|
||||
disable = ${toLuaObject cfg.indent.disable},
|
||||
},
|
||||
|
||||
-- Highlight module for Treesitter
|
||||
highlight = {
|
||||
enable = ${toLuaObject cfg.highlight.enable},
|
||||
disable = ${toLuaObject cfg.highlight.disable},
|
||||
additional_vim_regex_highlighting = ${toLuaObject cfg.highlight.additionalVimRegexHighlighting},
|
||||
},
|
||||
|
||||
-- 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 = {
|
||||
enable = true,
|
||||
enable = ${toLuaObject cfg.incrementalSelection.enable},
|
||||
disable = ${toLuaObject cfg.incrementalSelection.disable},
|
||||
keymaps = {
|
||||
init_selection = false,
|
||||
node_incremental = false,
|
||||
scope_incremental = false,
|
||||
node_decremental = false,
|
||||
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,89 +0,0 @@
|
|||
{
|
||||
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;
|
||||
cfg = treesitter.context;
|
||||
in {
|
||||
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;
|
||||
default = 0;
|
||||
};
|
||||
|
||||
minWindowHeight = mkOption {
|
||||
description = "Minimum editor window height to enable context. Values <= 0 mean no limit.";
|
||||
type = int;
|
||||
default = 0;
|
||||
};
|
||||
|
||||
lineNumbers = mkOption {
|
||||
description = "";
|
||||
type = bool;
|
||||
default = true;
|
||||
};
|
||||
|
||||
multilineThreshold = mkOption {
|
||||
description = "Maximum number of lines to collapse for a single context line.";
|
||||
type = int;
|
||||
default = 20;
|
||||
};
|
||||
|
||||
trimScope = mkOption {
|
||||
description = "Which context lines to discard if [](#opt-vim.treesitter.context.maxLines) is exceeded.";
|
||||
type = enum ["inner" "outer"];
|
||||
default = "outer";
|
||||
};
|
||||
|
||||
mode = mkOption {
|
||||
description = "Line used to calculate context.";
|
||||
type = enum ["cursor" "topline"];
|
||||
default = "cursor";
|
||||
};
|
||||
|
||||
separator = mkOption {
|
||||
description = ''
|
||||
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;
|
||||
default = null;
|
||||
};
|
||||
|
||||
zindex = mkOption {
|
||||
description = "The Z-index of the context window.";
|
||||
type = int;
|
||||
default = 20;
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf (treesitter.enable && cfg.enable) {
|
||||
vim.startPlugins = ["nvim-treesitter-context"];
|
||||
|
||||
vim.luaConfigRC.treesitter-context = entryAnywhere ''
|
||||
require'treesitter-context'.setup {
|
||||
enable = true,
|
||||
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},
|
||||
max_lines = ${toString cfg.zindex},
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
{
|
||||
imports = [
|
||||
# treesitter extras
|
||||
./ts-context
|
||||
|
||||
./treesitter.nix
|
||||
./context.nix
|
||||
./config.nix
|
||||
];
|
||||
}
|
||||
|
|
|
@ -1,20 +1,15 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.options) mkOption mkEnableOption literalMD literalExpression;
|
||||
inherit (lib.types) listOf package str either bool;
|
||||
inherit (lib.nvim.binds) mkMappingOption;
|
||||
inherit (lib.types) listOf package;
|
||||
inherit (lib.nvim.types) luaInline;
|
||||
in {
|
||||
options.vim.treesitter = {
|
||||
enable = mkEnableOption "treesitter, also enabled automatically through language options";
|
||||
fold = mkEnableOption "fold with treesitter";
|
||||
autotagHtml = mkEnableOption "autoclose and rename html tag";
|
||||
grammars = mkOption {
|
||||
type = listOf package;
|
||||
default = [];
|
||||
description = ''
|
||||
List of treesitter grammars to install. For supported languages
|
||||
use the `vim.language.<lang>.treesitter` option
|
||||
'';
|
||||
};
|
||||
|
||||
mappings.incrementalSelection = {
|
||||
init = mkMappingOption "Init selection [treesitter]" "gnn";
|
||||
|
@ -22,5 +17,152 @@ in {
|
|||
incrementByScope = mkMappingOption "Increment selection by scope [treesitter]" "grc";
|
||||
decrementByNode = mkMappingOption "Decrement selection by node [treesitter]" "grm";
|
||||
};
|
||||
|
||||
fold = mkEnableOption "fold with treesitter";
|
||||
autotagHtml = mkEnableOption "autoclose and rename html tag";
|
||||
|
||||
grammars = mkOption {
|
||||
type = listOf package;
|
||||
default = [];
|
||||
description = ''
|
||||
List of treesitter grammars to install.
|
||||
|
||||
For languages already supported by neovim-flake, you may
|
||||
use the {option}`vim.language.<lang>.treesitter` options, which
|
||||
will automatically add the required grammars to this.
|
||||
'';
|
||||
};
|
||||
|
||||
addDefaultGrammars = mkOption {
|
||||
type = bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether to add the default grammars to the list of grammars
|
||||
to install.
|
||||
This option is only relevant if treesitter has been enabled.
|
||||
'';
|
||||
};
|
||||
|
||||
defaultGrammars = mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = listOf package;
|
||||
default = with pkgs.vimPlugins.nvim-treesitter.builtGrammars; [c lua vim vimdoc query];
|
||||
description = ''
|
||||
A list of treesitter grammars that will be installed by default
|
||||
if treesitter has been enabled and {option}`vim.treeesitter.addDefaultGrammars`
|
||||
has been set to true.
|
||||
|
||||
::: {.note}
|
||||
Regardless of which language module options you enable, Neovim
|
||||
depends on those grammars to be enabled while treesitter is enabled.
|
||||
|
||||
This list cannot be modified, but if you would like to bring your own
|
||||
parsers instead of those provided here, you can set `addDefaultGrammars`
|
||||
to false
|
||||
:::
|
||||
'';
|
||||
};
|
||||
|
||||
indent = {
|
||||
enable = mkEnableOption "indentation with treesitter" // {default = true;};
|
||||
disable = mkOption {
|
||||
type = either (listOf str) luaInline;
|
||||
default = [];
|
||||
example = literalExpression ''["c" "rust"]'';
|
||||
|
||||
description = ''
|
||||
List of treesitter grammars to disable indentation for.
|
||||
|
||||
This option can be either a list, in which case it will be
|
||||
converted to a Lua table containing grammars to disable
|
||||
indentation for, or a string containing a **lua function**
|
||||
that will be read as is.
|
||||
|
||||
::: {.warning}
|
||||
A comma will be added at the end of your function, so you
|
||||
do not need to add it yourself. Doing so will cause in
|
||||
syntax errors within your Neovim configuration.
|
||||
:::
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
highlight = {
|
||||
enable = mkEnableOption "highlighting with treesitter" // {default = true;};
|
||||
disable = mkOption {
|
||||
type = either (listOf str) luaInline;
|
||||
default = [];
|
||||
example = literalMD ''
|
||||
```lua
|
||||
-- Disable slow treesitter highlight for large files
|
||||
disable = function(lang, buf)
|
||||
local max_filesize = 1000 * 1024 -- 1MB
|
||||
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
|
||||
if ok and stats and stats.size > max_filesize then
|
||||
return true
|
||||
end
|
||||
end
|
||||
```
|
||||
'';
|
||||
|
||||
description = ''
|
||||
List of treesitter grammars to disable highlighting for.
|
||||
|
||||
This option can be either a list, in which case it will be
|
||||
converted to a Lua table containing grammars to disable
|
||||
highlighting for, or a string containing a **lua function**
|
||||
that will be read as is.
|
||||
|
||||
::: {.warning}
|
||||
A comma will be added at the end of your function, so you
|
||||
do not need to add it yourself. Doing so will cause in
|
||||
syntax errors within your Neovim configuration.
|
||||
:::
|
||||
'';
|
||||
};
|
||||
|
||||
additionalVimRegexHighlighting = mkOption {
|
||||
type = either bool (listOf str);
|
||||
default = false;
|
||||
description = ''
|
||||
Takes either a boolean or a list of languages.
|
||||
|
||||
Setting this to true will run `:h syntax` and tree-sitter at the same time.
|
||||
You may this to `true` if you depend on 'syntax' being enabled (like for
|
||||
indentation).
|
||||
|
||||
::: {.note}
|
||||
Using this option may slow down your editor, and you may see some duplicate
|
||||
highlights.
|
||||
:::
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
incrementalSelection = {
|
||||
enable = mkEnableOption "incremental selection with treesitter" // {default = true;};
|
||||
disable = mkOption {
|
||||
type = either (listOf str) luaInline;
|
||||
default = [];
|
||||
example = literalExpression ''["c" "rust" ]'';
|
||||
|
||||
description = ''
|
||||
List of treesitter grammars to disable incremental selection
|
||||
for.
|
||||
|
||||
This option can be either a list, in which case it will be
|
||||
converted to a Lua table containing grammars to disable
|
||||
indentation for, or a string containing a **lua function**
|
||||
that will be read as is.
|
||||
|
||||
::: {.warning}
|
||||
A comma will be added at the end of your function, so you
|
||||
do not need to add it yourself. Doing so will cause in
|
||||
syntax errors within your Neovim configuration.
|
||||
:::
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
24
modules/plugins/treesitter/ts-context/config.nix
Normal file
24
modules/plugins/treesitter/ts-context/config.nix
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.nvim.lua) toLuaObject;
|
||||
inherit (lib.nvim.dag) entryAfter;
|
||||
|
||||
inherit (config.vim) treesitter;
|
||||
cfg = treesitter.context;
|
||||
in {
|
||||
config = mkIf (treesitter.enable && cfg.enable) {
|
||||
vim = {
|
||||
startPlugins = ["nvim-treesitter-context"];
|
||||
|
||||
# set up treesitter-context after Treesitter. The ordering
|
||||
# should not matter, but there is no harm in doing this
|
||||
luaConfigRC.treesitter-context = entryAfter ["treesitter"] ''
|
||||
require("treesitter-context").setup(${toLuaObject cfg.setupOpts})
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
94
modules/plugins/treesitter/ts-context/context.nix
Normal file
94
modules/plugins/treesitter/ts-context/context.nix
Normal file
|
@ -0,0 +1,94 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
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 {
|
||||
imports = renamedSetupOpts;
|
||||
options.vim.treesitter.context = {
|
||||
enable = mkEnableOption "context of current buffer contents [nvim-treesitter-context] ";
|
||||
|
||||
setupOpts = mkPluginSetupOption "treesitter-context" {
|
||||
max_lines = mkOption {
|
||||
type = int;
|
||||
default = 0;
|
||||
description = ''
|
||||
How many lines the window should span.
|
||||
|
||||
Values >= 0 mean there will be no limit.
|
||||
'';
|
||||
};
|
||||
|
||||
min_window_height = mkOption {
|
||||
type = int;
|
||||
default = 0;
|
||||
description = ''
|
||||
Minimum editor window height to enable context.
|
||||
|
||||
Values >= 0 mean there will be no limit.
|
||||
'';
|
||||
};
|
||||
|
||||
line_numbers = mkOption {
|
||||
type = bool;
|
||||
default = true;
|
||||
description = "Whether to display line numbers in current context";
|
||||
};
|
||||
|
||||
multiline_threshold = mkOption {
|
||||
type = int;
|
||||
default = 20;
|
||||
description = "Maximum number of lines to collapse for a single context line.";
|
||||
};
|
||||
|
||||
trim_scope = mkOption {
|
||||
type = enum ["inner" "outer"];
|
||||
default = "outer";
|
||||
description = ''
|
||||
Which context lines to discard if
|
||||
[](#opt-vim.treesitter.context.setupOpts.max_lines) is exceeded.
|
||||
'';
|
||||
};
|
||||
|
||||
mode = mkOption {
|
||||
type = enum ["cursor" "topline"];
|
||||
default = "cursor";
|
||||
description = "Line used to calculate context.";
|
||||
};
|
||||
|
||||
separator = mkOption {
|
||||
type = nullOr str;
|
||||
default = "-";
|
||||
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.";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
6
modules/plugins/treesitter/ts-context/default.nix
Normal file
6
modules/plugins/treesitter/ts-context/default.nix
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
imports = [
|
||||
./context.nix
|
||||
./config.nix
|
||||
];
|
||||
}
|
|
@ -1,75 +1,93 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.lists) optionals;
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.trivial) boolToString;
|
||||
inherit (lib.nvim.dag) entryAnywhere;
|
||||
|
||||
cfg = config.vim.ui.noice;
|
||||
tscfg = config.vim.treesitter;
|
||||
cmptype = config.vim.autocomplete.type;
|
||||
|
||||
defaultGrammars = with pkgs.vimPlugins.nvim-treesitter.builtGrammars; [vim regex lua bash markdown];
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim.startPlugins = [
|
||||
"noice-nvim"
|
||||
"nui-nvim"
|
||||
];
|
||||
vim = {
|
||||
startPlugins = [
|
||||
"noice-nvim"
|
||||
"nui-nvim"
|
||||
];
|
||||
|
||||
vim.luaConfigRC.noice-nvim = entryAnywhere ''
|
||||
require("noice").setup({
|
||||
lsp = {
|
||||
override = {
|
||||
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
|
||||
["vim.lsp.util.stylize_markdown"] = true,
|
||||
["cmp.entry.get_documentation"] = true,
|
||||
},
|
||||
treesitter.grammars = optionals tscfg.addDefaultGrammars defaultGrammars;
|
||||
|
||||
signature = {
|
||||
enabled = false, -- FIXME: enabling this file throws an error which I couldn't figure out
|
||||
},
|
||||
},
|
||||
|
||||
presets = {
|
||||
bottom_search = true, -- use a classic bottom cmdline for search
|
||||
command_palette = true, -- position the cmdline and popupmenu together
|
||||
long_message_to_split = true, -- long messages will be sent to a split
|
||||
inc_rename = false, -- enables an input dialog for inc-rename.nvim
|
||||
lsp_doc_border = ${boolToString config.vim.ui.borders.enable}, -- add a border to hover docs and signature help
|
||||
},
|
||||
|
||||
format = {
|
||||
cmdline = { pattern = "^:", icon = "", lang = "vim" },
|
||||
search_down = { kind = "search", pattern = "^/", icon = " ", lang = "regex" },
|
||||
search_up = { kind = "search", pattern = "^%?", icon = " ", lang = "regex" },
|
||||
filter = { pattern = "^:%s*!", icon = "", lang = "bash" },
|
||||
lua = { pattern = "^:%s*lua%s+", icon = "", lang = "lua" },
|
||||
help = { pattern = "^:%s*he?l?p?%s+", icon = "" },
|
||||
input = {},
|
||||
},
|
||||
|
||||
messages = {
|
||||
-- NOTE: If you enable messages, then the cmdline is enabled automatically.
|
||||
-- This is a current Neovim limitation.
|
||||
enabled = false, -- enables the Noice messages UI
|
||||
view = "notify", -- default view for messages
|
||||
view_error = "notify", -- view for errors
|
||||
view_warn = "notify", -- view for warnings
|
||||
view_history = "messages", -- view for :messages
|
||||
view_search = "virtualtext", -- view for search count messages. Set to `false` to disable
|
||||
},
|
||||
|
||||
-- Hide written messages
|
||||
routes = {
|
||||
{
|
||||
filter = {
|
||||
event = "msg_show",
|
||||
kind = "",
|
||||
find = "written",
|
||||
luaConfigRC.noice-nvim = entryAnywhere ''
|
||||
require("noice").setup({
|
||||
lsp = {
|
||||
override = {
|
||||
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
|
||||
["vim.lsp.util.stylize_markdown"] = true,
|
||||
${optionalString (cmptype == "nvim-cmp") "[\"cmp.entry.get_documentation\"] = true,"}
|
||||
},
|
||||
|
||||
signature = {
|
||||
enabled = false, -- FIXME: enabling this file throws an error which I couldn't figure out
|
||||
},
|
||||
opts = { skip = true },
|
||||
},
|
||||
},
|
||||
})
|
||||
'';
|
||||
|
||||
hover = {
|
||||
enabled = true,
|
||||
silent = false, -- set to true to not show a message if hover is not available
|
||||
view = nil, -- when nil, use defaults from documentation
|
||||
opts = {}, -- merged with defaults from documentation
|
||||
},
|
||||
|
||||
presets = {
|
||||
bottom_search = true, -- use a classic bottom cmdline for search
|
||||
command_palette = true, -- position the cmdline and popupmenu together
|
||||
long_message_to_split = true, -- long messages will be sent to a split
|
||||
inc_rename = false, -- enables an input dialog for inc-rename.nvim
|
||||
lsp_doc_border = ${boolToString config.vim.ui.borders.enable}, -- add a border to hover docs and signature help
|
||||
},
|
||||
|
||||
format = {
|
||||
cmdline = { pattern = "^:", icon = "", lang = "vim" },
|
||||
search_down = { kind = "search", pattern = "^/", icon = " ", lang = "regex" },
|
||||
search_up = { kind = "search", pattern = "^%?", icon = " ", lang = "regex" },
|
||||
filter = { pattern = "^:%s*!", icon = "", lang = "bash" },
|
||||
lua = { pattern = "^:%s*lua%s+", icon = "", lang = "lua" },
|
||||
help = { pattern = "^:%s*he?l?p?%s+", icon = "" },
|
||||
input = {},
|
||||
},
|
||||
|
||||
messages = {
|
||||
-- NOTE: If you enable messages, then the cmdline is enabled automatically.
|
||||
-- This is a current Neovim limitation.
|
||||
enabled = true, -- enables the Noice messages UI
|
||||
view = "notify", -- default view for messages
|
||||
view_error = "notify", -- view for errors
|
||||
view_warn = "notify", -- view for warnings
|
||||
view_history = "messages", -- view for :messages
|
||||
view_search = "virtualtext", -- view for search count messages. Set to `false` to disable
|
||||
},
|
||||
|
||||
-- Hide written messages
|
||||
routes = {
|
||||
{
|
||||
filter = {
|
||||
event = "msg_show",
|
||||
kind = "",
|
||||
find = "written",
|
||||
},
|
||||
opts = { skip = true },
|
||||
},
|
||||
},
|
||||
})
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue