From 495e7620d21771c8217e1b65b68d6d3061ac305c Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 23 Apr 2024 16:08:36 +0300 Subject: [PATCH 01/16] plugins/treesitter: move nvim-treesitter-context to its own dir --- .../plugins/treesitter/ts-context/config.nix | 31 ++++++++++ .../plugins/treesitter/ts-context/context.nix | 60 +++++++++++++++++++ .../plugins/treesitter/ts-context/default.nix | 6 ++ 3 files changed, 97 insertions(+) create mode 100644 modules/plugins/treesitter/ts-context/config.nix create mode 100644 modules/plugins/treesitter/ts-context/context.nix create mode 100644 modules/plugins/treesitter/ts-context/default.nix diff --git a/modules/plugins/treesitter/ts-context/config.nix b/modules/plugins/treesitter/ts-context/config.nix new file mode 100644 index 0000000..89ac74c --- /dev/null +++ b/modules/plugins/treesitter/ts-context/config.nix @@ -0,0 +1,31 @@ +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkIf; + inherit (lib.trivial) boolToString; + inherit (lib.nvim.lua) nullString; + inherit (lib.nvim.dag) entryAfter; + + inherit (config.vim) treesitter; + cfg = treesitter.context; +in { + config = mkIf (treesitter.enable && cfg.enable) { + vim.startPlugins = ["nvim-treesitter-context"]; + + vim.luaConfigRC.treesitter-context = entryAfter ["treesitter"] '' + 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}, + } + ''; + }; +} diff --git a/modules/plugins/treesitter/ts-context/context.nix b/modules/plugins/treesitter/ts-context/context.nix new file mode 100644 index 0000000..387aa81 --- /dev/null +++ b/modules/plugins/treesitter/ts-context/context.nix @@ -0,0 +1,60 @@ +{lib, ...}: let + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) int bool str nullOr enum; +in { + options.vim.treesitter.context = { + enable = mkEnableOption "context of current buffer contents [nvim-treesitter-context] "; + + maxLines = mkOption { + type = int; + default = 0; + description = "How many lines the window should span. Values <=0 mean no limit."; + }; + + minWindowHeight = mkOption { + type = int; + default = 0; + description = "Minimum editor window height to enable context. Values <= 0 mean no limit."; + }; + + lineNumbers = mkOption { + type = bool; + default = true; + description = ""; + }; + + multilineThreshold = mkOption { + type = int; + default = 20; + description = "Maximum number of lines to collapse for a single context line."; + }; + + trimScope = mkOption { + type = enum ["inner" "outer"]; + default = "outer"; + description = "Which context lines to discard if [](#opt-vim.treesitter.context.maxLines) is exceeded."; + }; + + mode = mkOption { + type = enum ["cursor" "topline"]; + default = "cursor"; + description = "Line used to calculate context."; + }; + + separator = mkOption { + type = nullOr str; + default = null; + 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. + ''; + }; + + zindex = mkOption { + type = int; + default = 20; + description = "The Z-index of the context window."; + }; + }; +} diff --git a/modules/plugins/treesitter/ts-context/default.nix b/modules/plugins/treesitter/ts-context/default.nix new file mode 100644 index 0000000..bf53d2b --- /dev/null +++ b/modules/plugins/treesitter/ts-context/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./context.nix + ./config.nix + ]; +} From 7fd653b4d8aa2c0b1777f49918b0321139f2636e Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 23 Apr 2024 16:08:55 +0300 Subject: [PATCH 02/16] plugins/treesitter: add an internal `defaultGrammars` options --- modules/plugins/treesitter/config.nix | 14 ++-- modules/plugins/treesitter/context.nix | 89 ----------------------- modules/plugins/treesitter/default.nix | 4 +- modules/plugins/treesitter/treesitter.nix | 50 ++++++++++--- 4 files changed, 51 insertions(+), 106 deletions(-) delete mode 100644 modules/plugins/treesitter/context.nix diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index 92802a8..e4d6c24 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -1,5 +1,6 @@ { config, + pkgs, lib, ... }: let @@ -11,7 +12,7 @@ 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 { @@ -32,7 +33,6 @@ in { (mkSetBinding mappings.incrementalSelection.decrementByNode ":lua require('nvim-treesitter.incremental_selection').node_decremental()") ]; }; - # 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"] '' set foldmethod=expr @@ -42,14 +42,18 @@ in { luaConfigRC.treesitter = entryAnywhere '' require'nvim-treesitter.configs'.setup { + -- Disable imperative treesitter options that would attempt to fetch + -- grammars into the read-only Nix store. To add additionall grammars here + -- you must use the `config.vim.treesitter.grammars` option. + auto_install = false, + sync_install = false, + ensure_installed = {}, + highlight = { enable = true, disable = {}, }, - auto_install = false, - ensure_installed = {}, - incremental_selection = { enable = true, keymaps = { diff --git a/modules/plugins/treesitter/context.nix b/modules/plugins/treesitter/context.nix deleted file mode 100644 index 8bb65b5..0000000 --- a/modules/plugins/treesitter/context.nix +++ /dev/null @@ -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}, - } - ''; - }; -} diff --git a/modules/plugins/treesitter/default.nix b/modules/plugins/treesitter/default.nix index 5520cfe..a859f3a 100644 --- a/modules/plugins/treesitter/default.nix +++ b/modules/plugins/treesitter/default.nix @@ -1,7 +1,9 @@ { imports = [ + # treesitter extras + ./ts-context + ./treesitter.nix - ./context.nix ./config.nix ]; } diff --git a/modules/plugins/treesitter/treesitter.nix b/modules/plugins/treesitter/treesitter.nix index feae8d7..373f0ee 100644 --- a/modules/plugins/treesitter/treesitter.nix +++ b/modules/plugins/treesitter/treesitter.nix @@ -1,20 +1,16 @@ -{lib, ...}: let +{ + pkgs, + lib, + ... +}: let inherit (lib.options) mkOption mkEnableOption; inherit (lib.nvim.binds) mkMappingOption; inherit (lib.types) listOf package; + + inherit (pkgs.vimPlugins.nvim-treesitter) builtGrammars; 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..treesitter` option - ''; - }; mappings.incrementalSelection = { init = mkMappingOption "Init selection [treesitter]" "gnn"; @@ -22,5 +18,37 @@ 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..treesitter` options, which + will automatically add the required grammars to this. + ''; + }; + + defaultGrammars = mkOption { + internal = true; + readOnly = true; + type = listOf package; + default = with builtGrammars; [c lua vim vimdoc query]; + description = '' + A list of treesitter grammars that will be installed by default + if treesitter has been enabled. + + ::: {.warning} + 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 its contents will only be appended + if the list of grammars does not contain the required grammars. + ::: + ''; + }; }; } From b614dc6b4139035a9c33554831aec4b439955f39 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 23 Apr 2024 16:17:09 +0300 Subject: [PATCH 03/16] lib/lists: init; add `listContainsValue` Helps us validate lists that contain a bunch of values and see if it contains a desired list of values --- lib/default.nix | 1 + lib/lists.nix | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 lib/lists.nix diff --git a/lib/default.nix b/lib/default.nix index 693aff9..eade2e2 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -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; } diff --git a/lib/lists.nix b/lib/lists.nix new file mode 100644 index 0000000..25e85ad --- /dev/null +++ b/lib/lists.nix @@ -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; +} From 49b705b6aa43762240755b4f9c737e291297226e Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 23 Apr 2024 16:24:00 +0300 Subject: [PATCH 04/16] plugins/treesitter: fix typo in doc comment --- modules/plugins/treesitter/config.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index e4d6c24..e91e5cd 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -43,7 +43,7 @@ in { luaConfigRC.treesitter = entryAnywhere '' require'nvim-treesitter.configs'.setup { -- Disable imperative treesitter options that would attempt to fetch - -- grammars into the read-only Nix store. To add additionall grammars here + -- 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, From 5e08ed42e74e1aeb5ccec71d0e50de5fb50337f3 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 23 Apr 2024 16:48:39 +0300 Subject: [PATCH 05/16] plugins/treesitter: allow `highlight` to be fine-grained --- modules/plugins/treesitter/config.nix | 6 ++-- modules/plugins/treesitter/treesitter.nix | 40 +++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index e91e5cd..8fee4dc 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -6,7 +6,9 @@ }: let inherit (lib.modules) mkIf mkMerge; inherit (lib.lists) optional; + inherit (lib.trivial) boolToString; inherit (lib.nvim.binds) mkSetBinding addDescriptionsToMappings; + inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.dag) entryBefore entryAnywhere; cfg = config.vim.treesitter; @@ -50,8 +52,8 @@ in { ensure_installed = {}, highlight = { - enable = true, - disable = {}, + enable = ${boolToString cfg.highlight.enable}, + disable = ${toLuaObject cfg.highlight.disable}, }, incremental_selection = { diff --git a/modules/plugins/treesitter/treesitter.nix b/modules/plugins/treesitter/treesitter.nix index 373f0ee..74c1b62 100644 --- a/modules/plugins/treesitter/treesitter.nix +++ b/modules/plugins/treesitter/treesitter.nix @@ -3,9 +3,10 @@ lib, ... }: let - inherit (lib.options) mkOption mkEnableOption; + inherit (lib.options) mkOption mkEnableOption literalMD; inherit (lib.nvim.binds) mkMappingOption; - inherit (lib.types) listOf package; + inherit (lib.types) listOf package str either; + inherit (lib.nvim.types) luaInline; inherit (pkgs.vimPlugins.nvim-treesitter) builtGrammars; in { @@ -33,6 +34,41 @@ in { ''; }; + highlight = { + enable = mkEnableOption "highlighting with treesitter"; + disable = mkOption { + type = either (luaInline (listOf str)); + 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. + ::: + ''; + }; + }; + defaultGrammars = mkOption { internal = true; readOnly = true; From 5e12c2315a688ce5af764ddef8a1c804de4f7f65 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 23 Apr 2024 20:20:49 +0300 Subject: [PATCH 06/16] plugins/treesitter: allow user to toggle default grammars --- modules/plugins/treesitter/config.nix | 17 +++++++++++-- modules/plugins/treesitter/treesitter.nix | 31 +++++++++++++++-------- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index 8fee4dc..cf1d595 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -5,8 +5,9 @@ ... }: let inherit (lib.modules) mkIf mkMerge; - inherit (lib.lists) optional; + inherit (lib.lists) optional optionals; inherit (lib.trivial) boolToString; + inherit (lib.nvim.lists) listContainsValues; inherit (lib.nvim.binds) mkSetBinding addDescriptionsToMappings; inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.dag) entryBefore entryAnywhere; @@ -23,6 +24,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,6 +37,7 @@ in { (mkSetBinding mappings.incrementalSelection.decrementByNode ":lua require('nvim-treesitter.incremental_selection').node_decremental()") ]; }; + # 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"] '' set foldmethod=expr @@ -43,7 +46,7 @@ in { ''); luaConfigRC.treesitter = entryAnywhere '' - require'nvim-treesitter.configs'.setup { + 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. @@ -51,13 +54,23 @@ in { sync_install = false, ensure_installed = {}, + -- Indentation module for Treesitter + indent = { + enable = true, + disable = {}, + }, + + -- Highlight module for Treesitter highlight = { enable = ${boolToString cfg.highlight.enable}, disable = ${toLuaObject cfg.highlight.disable}, + additional_vim_regex_highlighting = false, }, + -- Indentation module for Treesitter incremental_selection = { enable = true, + disable = {}, keymaps = { init_selection = false, node_incremental = false, diff --git a/modules/plugins/treesitter/treesitter.nix b/modules/plugins/treesitter/treesitter.nix index 74c1b62..1ff4dfe 100644 --- a/modules/plugins/treesitter/treesitter.nix +++ b/modules/plugins/treesitter/treesitter.nix @@ -4,11 +4,9 @@ ... }: let inherit (lib.options) mkOption mkEnableOption literalMD; + inherit (lib.types) listOf package str either bool; inherit (lib.nvim.binds) mkMappingOption; - inherit (lib.types) listOf package str either; - inherit (lib.nvim.types) luaInline; - - inherit (pkgs.vimPlugins.nvim-treesitter) builtGrammars; + inherit (lib.nvim.types) luaInline mkGrammarOption; in { options.vim.treesitter = { enable = mkEnableOption "treesitter, also enabled automatically through language options"; @@ -37,7 +35,7 @@ in { highlight = { enable = mkEnableOption "highlighting with treesitter"; disable = mkOption { - type = either (luaInline (listOf str)); + type = either (listOf str) luaInline; default = []; example = literalMD '' ```lua @@ -69,20 +67,33 @@ in { }; }; + 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 builtGrammars; [c lua vim vimdoc query]; + 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. + if treesitter has been enabled and {option}`vim.treeesitter.addDefaultGrammars` + has been set to true. - ::: {.warning} + ::: {.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 its contents will only be appended - if the list of grammars does not contain the required grammars. + + 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 ::: ''; }; From ad9d0c6cdb35bad5cd0cc2a3197262ad51265dd7 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 23 Apr 2024 20:43:41 +0300 Subject: [PATCH 07/16] ui/noice: add missing treesitter grammars --- modules/plugins/ui/noice/config.nix | 132 ++++++++++++++++------------ 1 file changed, 75 insertions(+), 57 deletions(-) diff --git a/modules/plugins/ui/noice/config.nix b/modules/plugins/ui/noice/config.nix index 63c4f2b..8d84584 100644 --- a/modules/plugins/ui/noice/config.nix +++ b/modules/plugins/ui/noice/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 }, + }, + }, + }) + ''; + }; }; } From feb7cd731ef21501916333c04ffcc9701db55381 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Wed, 24 Apr 2024 23:34:39 +0300 Subject: [PATCH 08/16] plugins/treesitter: write setup options after `basic` DAG --- modules/plugins/treesitter/config.nix | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index cf1d595..fd841b0 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -7,10 +7,9 @@ inherit (lib.modules) mkIf mkMerge; inherit (lib.lists) optional optionals; inherit (lib.trivial) boolToString; - inherit (lib.nvim.lists) listContainsValues; inherit (lib.nvim.binds) mkSetBinding addDescriptionsToMappings; inherit (lib.nvim.lua) toLuaObject; - inherit (lib.nvim.dag) entryBefore entryAnywhere; + inherit (lib.nvim.dag) entryBefore entryAfter; cfg = config.vim.treesitter; usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp"; @@ -45,7 +44,7 @@ in { set nofoldenable ''); - luaConfigRC.treesitter = entryAnywhere '' + 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 From 103941e270f5fcf794513297e4a46ac3dc4d53cf Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Wed, 24 Apr 2024 23:50:49 +0300 Subject: [PATCH 09/16] treesitter/ts-context: fix duplicate config entry --- modules/plugins/treesitter/ts-context/config.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/treesitter/ts-context/config.nix b/modules/plugins/treesitter/ts-context/config.nix index 89ac74c..a108959 100644 --- a/modules/plugins/treesitter/ts-context/config.nix +++ b/modules/plugins/treesitter/ts-context/config.nix @@ -24,7 +24,7 @@ in { trim_scope = '${cfg.trimScope}', mode = '${cfg.mode}', separator = ${nullString cfg.separator}, - max_lines = ${toString cfg.zindex}, + z_index = ${toString cfg.zindex}, } ''; }; From 92c94fda20855212571864bd3f2311be185358bf Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 25 Apr 2024 01:31:10 +0300 Subject: [PATCH 10/16] plugins/treesiter: set up fold after `basic` --- modules/plugins/treesitter/config.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index fd841b0..c7bd71a 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -37,11 +37,11 @@ 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"] '' + # For some reason treesitter highlighting does not work on start + # if this is set before syntax on + configRC.treesitter-fold = mkIf cfg.fold (entryAfter ["basic"] '' set foldmethod=expr set foldexpr=nvim_treesitter#foldexpr() - set nofoldenable ''); luaConfigRC.treesitter = entryAfter ["basic"] '' From 294109247042682bebb7493bdc99eaf886973df4 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 25 Apr 2024 01:36:58 +0300 Subject: [PATCH 11/16] Revert "plugins/treesiter: set up fold after `basic`" This reverts commit 92c94fda20855212571864bd3f2311be185358bf. --- modules/plugins/treesitter/config.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index c7bd71a..fd841b0 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -37,11 +37,11 @@ in { ]; }; - # For some reason treesitter highlighting does not work on start - # if this is set before syntax on - configRC.treesitter-fold = mkIf cfg.fold (entryAfter ["basic"] '' + # 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"] '' set foldmethod=expr set foldexpr=nvim_treesitter#foldexpr() + set nofoldenable ''); luaConfigRC.treesitter = entryAfter ["basic"] '' From 5246cf50dea1d1e944e8be3c853c159aa3aa5dd8 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 25 Apr 2024 01:48:55 +0300 Subject: [PATCH 12/16] plugins/theme: enable ts-context support for Catppuccin --- modules/plugins/theme/supported_themes.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/plugins/theme/supported_themes.nix b/modules/plugins/theme/supported_themes.nix index d504f86..dbddd11 100644 --- a/modules/plugins/theme/supported_themes.nix +++ b/modules/plugins/theme/supported_themes.nix @@ -58,6 +58,7 @@ gitsigns = true, telescope = true, treesitter = true, + treesitter_context = true, ts_rainbow = true, fidget = true, alpha = true, From e8035c42f45df8999fe7c75528ad11290fd629b9 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 25 Apr 2024 01:59:28 +0300 Subject: [PATCH 13/16] flake: bump inputs --- flake.lock | 60 +++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/flake.lock b/flake.lock index cca4f27..f590525 100644 --- a/flake.lock +++ b/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": { From c8d38872ab1babddbe08c1d7dfa28651a0a15b2d Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 28 Apr 2024 20:19:25 +0300 Subject: [PATCH 14/16] plugins/treesitter: migrate treesitter-context to new `setupOpts` --- modules/plugins/treesitter/config.nix | 8 ++ modules/plugins/treesitter/treesitter.nix | 2 +- .../plugins/treesitter/ts-context/config.nix | 25 ++-- .../plugins/treesitter/ts-context/context.nix | 118 +++++++++++------- 4 files changed, 94 insertions(+), 59 deletions(-) diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index fd841b0..fe8052f 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -39,8 +39,13 @@ 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 ''); @@ -67,6 +72,9 @@ in { }, -- 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, disable = {}, diff --git a/modules/plugins/treesitter/treesitter.nix b/modules/plugins/treesitter/treesitter.nix index 1ff4dfe..f228bdc 100644 --- a/modules/plugins/treesitter/treesitter.nix +++ b/modules/plugins/treesitter/treesitter.nix @@ -6,7 +6,7 @@ inherit (lib.options) mkOption mkEnableOption literalMD; inherit (lib.types) listOf package str either bool; inherit (lib.nvim.binds) mkMappingOption; - inherit (lib.nvim.types) luaInline mkGrammarOption; + inherit (lib.nvim.types) luaInline; in { options.vim.treesitter = { enable = mkEnableOption "treesitter, also enabled automatically through language options"; diff --git a/modules/plugins/treesitter/ts-context/config.nix b/modules/plugins/treesitter/ts-context/config.nix index a108959..df5c151 100644 --- a/modules/plugins/treesitter/ts-context/config.nix +++ b/modules/plugins/treesitter/ts-context/config.nix @@ -4,28 +4,21 @@ ... }: let inherit (lib.modules) mkIf; - inherit (lib.trivial) boolToString; - inherit (lib.nvim.lua) nullString; + 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"]; + vim = { + startPlugins = ["nvim-treesitter-context"]; - vim.luaConfigRC.treesitter-context = entryAfter ["treesitter"] '' - 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}, - z_index = ${toString cfg.zindex}, - } - ''; + # 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}) + ''; + }; }; } diff --git a/modules/plugins/treesitter/ts-context/context.nix b/modules/plugins/treesitter/ts-context/context.nix index 387aa81..61d029a 100644 --- a/modules/plugins/treesitter/ts-context/context.nix +++ b/modules/plugins/treesitter/ts-context/context.nix @@ -1,60 +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] "; - maxLines = mkOption { - type = int; - default = 0; - description = "How many lines the window should span. Values <=0 mean no limit."; - }; + setupOpts = mkPluginSetupOption "treesitter-context" { + max_lines = mkOption { + type = int; + default = 0; + description = '' + How many lines the window should span. - minWindowHeight = mkOption { - type = int; - default = 0; - description = "Minimum editor window height to enable context. Values <= 0 mean no limit."; - }; + Values >= 0 mean there will be no limit. + ''; + }; - lineNumbers = mkOption { - type = bool; - default = true; - description = ""; - }; + min_window_height = mkOption { + type = int; + default = 0; + description = '' + Minimum editor window height to enable context. - multilineThreshold = mkOption { - type = int; - default = 20; - description = "Maximum number of lines to collapse for a single context line."; - }; + Values >= 0 mean there will be no limit. + ''; + }; - trimScope = mkOption { - type = enum ["inner" "outer"]; - default = "outer"; - description = "Which context lines to discard if [](#opt-vim.treesitter.context.maxLines) is exceeded."; - }; + line_numbers = mkOption { + type = bool; + default = true; + description = "Whether to display line numbers in current context"; + }; - mode = mkOption { - type = enum ["cursor" "topline"]; - default = "cursor"; - description = "Line used to calculate context."; - }; + multiline_threshold = mkOption { + type = int; + default = 20; + description = "Maximum number of lines to collapse for a single context line."; + }; - separator = mkOption { - type = nullOr str; - default = null; - description = '' - Separator between context and content. Should be a single character string, like '-'. + 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. + ''; + }; - 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 { - type = int; - default = 20; - description = "The Z-index of the context window."; + 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."; + }; }; }; } From 616c00ab465a8dc076c8c7afcaa7b8d124c77d62 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 28 Apr 2024 21:04:28 +0300 Subject: [PATCH 15/16] plugins/treesitter: generate Lua configuration from Nix --- modules/plugins/treesitter/config.nix | 13 +- modules/plugins/treesitter/treesitter.nix | 139 ++++++++++++++++------ 2 files changed, 110 insertions(+), 42 deletions(-) diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index fe8052f..9c50753 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -60,15 +60,15 @@ in { -- Indentation module for Treesitter indent = { - enable = true, - disable = {}, + enable = ${toLuaObject cfg.indent.enable}, + disable = ${toLuaObject cfg.indent.disable}, }, -- Highlight module for Treesitter highlight = { - enable = ${boolToString cfg.highlight.enable}, + enable = ${toLuaObject cfg.highlight.enable}, disable = ${toLuaObject cfg.highlight.disable}, - additional_vim_regex_highlighting = false, + additional_vim_regex_highlighting = ${toLuaObject cfg.highlight.additionalVimRegexHighlighting}, }, -- Indentation module for Treesitter @@ -76,13 +76,14 @@ in { -- handled by `vim.maps` entries calling lua -- functions achieving the same functionality. incremental_selection = { - enable = true, - disable = {}, + enable = ${toLuaObject cfg.incrementalSelection.enable}, + disable = ${toLuaObject cfg.incrementalSelection.disable}, keymaps = { init_selection = false, node_incremental = false, scope_incremental = false, node_decremental = false, + }, }, } diff --git a/modules/plugins/treesitter/treesitter.nix b/modules/plugins/treesitter/treesitter.nix index f228bdc..916b796 100644 --- a/modules/plugins/treesitter/treesitter.nix +++ b/modules/plugins/treesitter/treesitter.nix @@ -3,7 +3,7 @@ lib, ... }: let - inherit (lib.options) mkOption mkEnableOption literalMD; + inherit (lib.options) mkOption mkEnableOption literalMD literalExpression; inherit (lib.types) listOf package str either bool; inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) luaInline; @@ -20,6 +20,7 @@ in { fold = mkEnableOption "fold with treesitter"; autotagHtml = mkEnableOption "autoclose and rename html tag"; + grammars = mkOption { type = listOf package; default = []; @@ -32,41 +33,6 @@ in { ''; }; - highlight = { - enable = mkEnableOption "highlighting with treesitter"; - 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. - ::: - ''; - }; - }; - addDefaultGrammars = mkOption { type = bool; default = true; @@ -97,5 +63,106 @@ in { ::: ''; }; + + 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. + ::: + ''; + }; + }; }; } From 694012dbd81ae7453e56bf2928b151d67e5857be Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 30 Apr 2024 08:08:54 +0300 Subject: [PATCH 16/16] neovim/init: override vim syntax highlighting with Treesitter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit see: «https://github.com/nvim-treesitter/nvim-treesitter/issues/2254» --- modules/neovim/init/basic.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/neovim/init/basic.nix b/modules/neovim/init/basic.nix index e3af1e7..3c8f0b3 100644 --- a/modules/neovim/init/basic.nix +++ b/modules/neovim/init/basic.nix @@ -49,7 +49,7 @@ in { syntaxHighlighting = mkOption { type = bool; - default = true; + default = !config.vim.treesitter.highlight.enable; description = "Enable syntax highlighting"; };