diff --git a/configuration.nix b/configuration.nix index 832bf95c..10a2ab5c 100644 --- a/configuration.nix +++ b/configuration.nix @@ -51,11 +51,9 @@ isMaximal: { css.enable = isMaximal; sql.enable = isMaximal; java.enable = isMaximal; - kotlin.enable = isMaximal; ts.enable = isMaximal; svelte.enable = isMaximal; go.enable = isMaximal; - lua.enable = isMaximal; elixir.enable = isMaximal; zig.enable = isMaximal; ocaml.enable = isMaximal; @@ -70,7 +68,6 @@ isMaximal: { lsp.server = "clangd"; }; - scala.enable = isMaximal; rust = { enable = isMaximal; crates.enable = isMaximal; @@ -108,10 +105,12 @@ isMaximal: { transparent = false; }; - autopairs.nvim-autopairs.enable = true; + autopairs.enable = true; - autocomplete.nvim-cmp.enable = true; - snippets.luasnip.enable = true; + autocomplete = { + enable = true; + type = "nvim-cmp"; + }; filetree = { nvimTree = { diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index 4941f093..660db08d 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -93,9 +93,6 @@ everyone. - Add dap-go for better dap configurations - Make noice.nvim customizable - Standardize border style options and add custom borders -- Remove `vim.disableDefaultRuntimePaths` in wrapper options. - - As nvf uses `$NVIM_APP_NAME` as of recent changes, we can safely assume any - configuration in `$XDG_CONFIG_HOME/nvf` is intentional. [rust-tools.nvim]: https://github.com/simrat39/rust-tools.nvim [rustaceanvim]: https://github.com/mrcjkb/rustaceanvim @@ -157,20 +154,6 @@ everyone. aren't defined in nvf. Move the alternate nvim-surround keybinds to use `setupOpts`. -- Remove `autopairs.type`, and rename `autopairs.enable` to - `autopairs.nvim-autopairs.enable`. The new - [](#opt-vim.autopairs.nvim-autopairs.enable) supports `setupOpts` format by - default. - -- Refactor of `nvim-cmp` and completion related modules - - Remove `autocomplete.type` in favor of per-plugin enable options such as - [](#opt-vim.autocomplete.nvim-cmp.enable). - - Deprecate legacy Vimsnip in favor of Luasnip, and integrate - friendly-snippets for bundled snippets. [](#opt-vim.snippets.luasnip.enable) - can be used to toggle Luasnip. - - Add sorting function options for completion sources under - [](#opt-vim.autocomplete.nvim-cmp.setupOpts.sorting.comparators) - [Neovim documentation on `vim.cmd`]: https://neovim.io/doc/user/lua.html#vim.cmd() - Make Neovim's configuration file entirely Lua based. This comes with a few @@ -263,17 +246,9 @@ everyone. - Add Otter support under `vim.lsp.otter` and an assert to prevent conflict with ccc - Add Neorg support under `vim.notes.neorg` -- Add LSP, diagnostics, formatter and Treesitter support for Kotlin under - `vim.languages.kotlin` -- changed default keybinds for leap.nvim to avoid altering expected behavior [Bloxx12](https://github.com/Bloxx12) - Add support for [base16 theming](https://github.com/RRethy/base16-nvim) under `vim.theme` - Fix internal breakage in `elixir-tools` setup. - -[ksonj](https://github.com/ksonj): - -- Add LSP support for Scala via - [nvim-metals](https://github.com/scalameta/nvim-metals) \ No newline at end of file diff --git a/flake.lock b/flake.lock index 34a22430..91014b9b 100644 --- a/flake.lock +++ b/flake.lock @@ -316,22 +316,6 @@ "type": "github" } }, - "plugin-cmp-luasnip": { - "flake": false, - "locked": { - "lastModified": 1696878902, - "narHash": "sha256-nUJJl2zyK/oSwz5RzI9j3gf9zpDfCImCYbPbVsyXgz8=", - "owner": "saadparwaiz1", - "repo": "cmp_luasnip", - "rev": "05a9ab28b53f71d1aece421ef32fee2cb857a843", - "type": "github" - }, - "original": { - "owner": "saadparwaiz1", - "repo": "cmp_luasnip", - "type": "github" - } - }, "plugin-cmp-nvim-lsp": { "flake": false, "locked": { @@ -380,6 +364,22 @@ "type": "github" } }, + "plugin-cmp-vsnip": { + "flake": false, + "locked": { + "lastModified": 1669100283, + "narHash": "sha256-2mkN03noOr5vBvRbSb35xZKorSH+8savQNZtgM9+QcM=", + "owner": "hrsh7th", + "repo": "cmp-vsnip", + "rev": "989a8a73c44e926199bfd05fa7a516d51f2d2752", + "type": "github" + }, + "original": { + "owner": "hrsh7th", + "repo": "cmp-vsnip", + "type": "github" + } + }, "plugin-codewindow-nvim": { "flake": false, "locked": { @@ -588,22 +588,6 @@ "type": "github" } }, - "plugin-friendly-snippets": { - "flake": false, - "locked": { - "lastModified": 1727061933, - "narHash": "sha256-yTsuV5unoujY0mhLINssYYBWCeefe+nJaxQHJKm7hlk=", - "owner": "rafamadriz", - "repo": "friendly-snippets", - "rev": "00ba9dd3df89509f95437b8d595553707c46d5ea", - "type": "github" - }, - "original": { - "owner": "rafamadriz", - "repo": "friendly-snippets", - "type": "github" - } - }, "plugin-gesture-nvim": { "flake": false, "locked": { @@ -860,22 +844,6 @@ "type": "github" } }, - "plugin-luasnip": { - "flake": false, - "locked": { - "lastModified": 1726165831, - "narHash": "sha256-nkaa1NGOI28Et2QitQB+Spv+J42QVdHE1oywteLcJJw=", - "owner": "L3MON4D3", - "repo": "LuaSnip", - "rev": "e808bee352d1a6fcf902ca1a71cee76e60e24071", - "type": "github" - }, - "original": { - "owner": "L3MON4D3", - "repo": "LuaSnip", - "type": "github" - } - }, "plugin-mind-nvim": { "flake": false, "locked": { @@ -1245,22 +1213,6 @@ "type": "github" } }, - "plugin-nvim-metals": { - "flake": false, - "locked": { - "lastModified": 1728295172, - "narHash": "sha256-ja/+MNxZ3H9io9jDwm5rhE6iKNi86a22eCOY75g19O8=", - "owner": "scalameta", - "repo": "nvim-metals", - "rev": "f861db9fda55939797ac1b05238c49b0dcdc3bdb", - "type": "github" - }, - "original": { - "owner": "scalameta", - "repo": "nvim-metals", - "type": "github" - } - }, "plugin-nvim-navbuddy": { "flake": false, "locked": { @@ -1869,6 +1821,22 @@ "type": "github" } }, + "plugin-vim-vsnip": { + "flake": false, + "locked": { + "lastModified": 1704937299, + "narHash": "sha256-gvm6z4pgSULBVPukewRyjwxZ0vZgreQWbG/0kOB1QBo=", + "owner": "hrsh7th", + "repo": "vim-vsnip", + "rev": "02a8e79295c9733434aab4e0e2b8c4b7cea9f3a9", + "type": "github" + }, + "original": { + "owner": "hrsh7th", + "repo": "vim-vsnip", + "type": "github" + } + }, "plugin-which-key": { "flake": false, "locked": { @@ -1923,10 +1891,10 @@ "plugin-cheatsheet-nvim": "plugin-cheatsheet-nvim", "plugin-cinnamon-nvim": "plugin-cinnamon-nvim", "plugin-cmp-buffer": "plugin-cmp-buffer", - "plugin-cmp-luasnip": "plugin-cmp-luasnip", "plugin-cmp-nvim-lsp": "plugin-cmp-nvim-lsp", "plugin-cmp-path": "plugin-cmp-path", "plugin-cmp-treesitter": "plugin-cmp-treesitter", + "plugin-cmp-vsnip": "plugin-cmp-vsnip", "plugin-codewindow-nvim": "plugin-codewindow-nvim", "plugin-comment-nvim": "plugin-comment-nvim", "plugin-copilot-cmp": "plugin-copilot-cmp", @@ -1940,7 +1908,6 @@ "plugin-fastaction-nvim": "plugin-fastaction-nvim", "plugin-fidget-nvim": "plugin-fidget-nvim", "plugin-flutter-tools": "plugin-flutter-tools", - "plugin-friendly-snippets": "plugin-friendly-snippets", "plugin-gesture-nvim": "plugin-gesture-nvim", "plugin-gitsigns-nvim": "plugin-gitsigns-nvim", "plugin-glow-nvim": "plugin-glow-nvim", @@ -1957,7 +1924,6 @@ "plugin-lspsaga": "plugin-lspsaga", "plugin-lua-utils-nvim": "plugin-lua-utils-nvim", "plugin-lualine": "plugin-lualine", - "plugin-luasnip": "plugin-luasnip", "plugin-mind-nvim": "plugin-mind-nvim", "plugin-minimap-vim": "plugin-minimap-vim", "plugin-modes-nvim": "plugin-modes-nvim", @@ -1981,7 +1947,6 @@ "plugin-nvim-docs-view": "plugin-nvim-docs-view", "plugin-nvim-lightbulb": "plugin-nvim-lightbulb", "plugin-nvim-lspconfig": "plugin-nvim-lspconfig", - "plugin-nvim-metals": "plugin-nvim-metals", "plugin-nvim-navbuddy": "plugin-nvim-navbuddy", "plugin-nvim-navic": "plugin-nvim-navic", "plugin-nvim-neoclip": "plugin-nvim-neoclip", @@ -2020,6 +1985,7 @@ "plugin-vim-markdown": "plugin-vim-markdown", "plugin-vim-repeat": "plugin-vim-repeat", "plugin-vim-startify": "plugin-vim-startify", + "plugin-vim-vsnip": "plugin-vim-vsnip", "plugin-which-key": "plugin-which-key", "rnix-lsp": "rnix-lsp", "systems": "systems_2" diff --git a/flake.nix b/flake.nix index d12bdc57..a1e58476 100644 --- a/flake.nix +++ b/flake.nix @@ -206,11 +206,6 @@ flake = false; }; - plugin-nvim-metals = { - url = "github:scalameta/nvim-metals"; - flake = false; - }; - # Copying/Registers plugin-registers = { url = "github:tversteeg/registers.nvim"; @@ -282,6 +277,11 @@ flake = false; }; + plugin-cmp-vsnip = { + url = "github:hrsh7th/cmp-vsnip"; + flake = false; + }; + plugin-cmp-path = { url = "github:hrsh7th/cmp-path"; flake = false; @@ -292,19 +292,9 @@ flake = false; }; - plugin-cmp-luasnip = { - url = "github:saadparwaiz1/cmp_luasnip"; - flake = false; - }; - # snippets - plugin-luasnip = { - url = "github:L3MON4D3/LuaSnip"; - flake = false; - }; - - plugin-friendly-snippets = { - url = "github:rafamadriz/friendly-snippets"; + plugin-vim-vsnip = { + url = "github:hrsh7th/vim-vsnip"; flake = false; }; diff --git a/lib/attrsets.nix b/lib/attrsets.nix deleted file mode 100644 index 59275af9..00000000 --- a/lib/attrsets.nix +++ /dev/null @@ -1,5 +0,0 @@ -{lib}: let - inherit (builtins) listToAttrs; -in { - mapListToAttrs = f: list: listToAttrs (map f list); -} diff --git a/lib/default.nix b/lib/default.nix index e6ccd2a7..a418cff8 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -10,7 +10,6 @@ dag = import ./dag.nix {inherit lib;}; languages = import ./languages.nix {inherit lib;}; lists = import ./lists.nix {inherit lib;}; - attrsets = import ./attrsets.nix {inherit lib;}; lua = import ./lua.nix {inherit lib;}; neovimConfiguration = import ../modules {inherit inputs lib;}; } diff --git a/lib/languages.nix b/lib/languages.nix index 52f1b5b8..e47202ee 100644 --- a/lib/languages.nix +++ b/lib/languages.nix @@ -2,8 +2,8 @@ {lib}: let inherit (builtins) isString getAttr; inherit (lib.options) mkOption; + inherit (lib.attrsets) listToAttrs; inherit (lib.types) bool; - inherit (lib.nvim.attrsets) mapListToAttrs; in { # Converts a boolean to a yes/no string. This is used in lots of # configuration formats. @@ -12,21 +12,21 @@ in { config, diagnosticsProviders, }: - mapListToAttrs - (v: let - type = - if isString v - then v - else getAttr v.type; - package = - if isString v - then diagnosticsProviders.${type}.package - else v.package; - in { - name = "${lang}-diagnostics-${type}"; - value = diagnosticsProviders.${type}.nullConfig package; - }) - config; + listToAttrs + (map (v: let + type = + if isString v + then v + else getAttr v.type; + package = + if isString v + then diagnosticsProviders.${type}.package + else v.package; + in { + name = "${lang}-diagnostics-${type}"; + value = diagnosticsProviders.${type}.nullConfig package; + }) + config); mkEnable = desc: mkOption { diff --git a/lib/types/default.nix b/lib/types/default.nix index 73b35956..70ca6bef 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -6,10 +6,10 @@ typesDag = import ./dag.nix {inherit lib;}; typesPlugin = import ./plugins.nix {inherit inputs lib;}; typesLanguage = import ./languages.nix {inherit lib;}; - customTypes = import ./custom.nix {inherit lib;}; + typesTypes = import ./types.nix {inherit lib;}; in { inherit (typesDag) dagOf; inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType; inherit (typesLanguage) diagnostics mkGrammarOption; - inherit (customTypes) anythingConcatLists char hexColor mergelessListOf; + inherit (typesTypes) anythingConcatLists char hexColor; } diff --git a/lib/types/custom.nix b/lib/types/types.nix similarity index 85% rename from lib/types/custom.nix rename to lib/types/types.nix index 3d4a2bcb..250d7636 100644 --- a/lib/types/custom.nix +++ b/lib/types/types.nix @@ -1,7 +1,7 @@ {lib}: let - inherit (lib.options) showOption showFiles getFiles mergeOneOption mergeEqualOption; - inherit (lib.strings) isString isStringLike; - inherit (lib.types) anything attrsOf listOf mkOptionType; + inherit (lib) isStringLike showOption showFiles getFiles mergeOneOption mergeEqualOption mkOptionType; + inherit (lib.strings) isString; + inherit (lib.types) anything attrsOf; inherit (lib.nvim.types) anythingConcatLists; inherit (builtins) typeOf isAttrs any head concatLists stringLength match; in { @@ -52,16 +52,6 @@ in { (mergeFunctions.${commonType} or mergeEqualOption) loc defs; }; - mergelessListOf = elemType: let - super = listOf elemType; - in - super - // { - name = "mergelessListOf"; - description = "mergeless ${super.description}"; - merge = mergeEqualOption; - }; - char = mkOptionType { name = "char"; description = "character"; diff --git a/modules/extra/deprecations.nix b/modules/extra/deprecations.nix index 779a7527..388913a7 100644 --- a/modules/extra/deprecations.nix +++ b/modules/extra/deprecations.nix @@ -1,5 +1,5 @@ {lib, ...}: let - inherit (lib.modules) mkRemovedOptionModule mkRenamedOptionModule; + inherit (lib.modules) mkRemovedOptionModule; in { imports = [ # 2024-06-06 @@ -14,40 +14,5 @@ in { available under `vim.ui.fastaction` as a replacement. Simply remove everything under `vim.lsp.nvimCodeActionMenu`, and set `vim.ui.fastaction.enable` to `true`. '') - - (mkRemovedOptionModule ["vim" "autopairs" "enable"] '' - vim.autopairs.enable has been removed in favor of per-plugin modules. - You can enable nvim-autopairs with vim.autopairs.nvim-autopairs.enable instead. - '') - (mkRemovedOptionModule ["vim" "autopairs" "type"] '' - vim.autopairs.type has been removed in favor of per-plugin modules. - You can enable nvim-autopairs with vim.autopairs.nvim-autopairs.enable instead. - '') - (mkRemovedOptionModule ["vim" "autocomplete" "enable"] '' - vim.autocomplete.enable has been removed in favor of per-plugin modules. - You can enable nvim-cmp with vim.autocomplete.nvim-cmp.enable instead. - '') - (mkRemovedOptionModule ["vim" "autocomplete" "type"] '' - vim.autocomplete.type has been removed in favor of per-plugin modules. - You can enable nvim-cmp with vim.autocomplete.nvim-cmp.enable instead. - '') - (mkRemovedOptionModule ["vim" "snippets" "vsnip" "enable"] '' - vim.snippets.vsnip.enable has been removed in favor of the more modern luasnip. - '') - (mkRenamedOptionModule ["vim" "lsp" "lspkind" "mode"] ["vim" "lsp" "lspkind" "setupOpts" "mode"]) - - # 2024-10-14 - (mkRemovedOptionModule ["vim" "configRC"] '' - Please migrate your configRC sections to Neovim's Lua format, and - add them to `vim.luaConfigRC`. - - See the v0.7 release notes for more information on why and how to - migrate your existing configurations to the new format. - '') - - (mkRemovedOptionModule ["vim" "disableDefaultRuntimePaths"] '' - Nvf now uses $NVIM_APP_NAME so there is no longer the problem of - (accidental) leaking of user configuration. - '') ]; } diff --git a/modules/plugins/assistant/copilot/config.nix b/modules/plugins/assistant/copilot/config.nix index 923a0c6d..c9e6f830 100644 --- a/modules/plugins/assistant/copilot/config.nix +++ b/modules/plugins/assistant/copilot/config.nix @@ -34,8 +34,6 @@ in { "copilot-cmp" ]; - vim.autocomplete.nvim-cmp.sources = {copilot = "[Copilot]";}; - vim.pluginRC.copilot = entryAnywhere '' require("copilot").setup(${toLuaObject cfg.setupOpts}) diff --git a/modules/plugins/autopairs/nvim-autopairs/config.nix b/modules/plugins/autopairs/nvim-autopairs/config.nix index 6566ec28..6ef7cbfb 100644 --- a/modules/plugins/autopairs/nvim-autopairs/config.nix +++ b/modules/plugins/autopairs/nvim-autopairs/config.nix @@ -4,17 +4,16 @@ ... }: let inherit (lib.modules) mkIf; + inherit (lib.trivial) boolToString; inherit (lib.nvim.dag) entryAnywhere; - inherit (lib.nvim.lua) toLuaObject; - cfg = config.vim.autopairs.nvim-autopairs; + cfg = config.vim.autopairs; in { config = mkIf cfg.enable { - vim = { - startPlugins = ["nvim-autopairs"]; - pluginRC.autopairs = entryAnywhere '' - require('nvim-autopairs').setup(${toLuaObject cfg.setupOpts}) - ''; - }; + vim.startPlugins = ["nvim-autopairs"]; + + vim.pluginRC.autopairs = entryAnywhere '' + require("nvim-autopairs").setup({ map_cr = ${boolToString (!config.vim.autocomplete.enable)} }) + ''; }; } diff --git a/modules/plugins/autopairs/nvim-autopairs/nvim-autopairs.nix b/modules/plugins/autopairs/nvim-autopairs/nvim-autopairs.nix index d3a2bc7f..7e456063 100644 --- a/modules/plugins/autopairs/nvim-autopairs/nvim-autopairs.nix +++ b/modules/plugins/autopairs/nvim-autopairs/nvim-autopairs.nix @@ -1,14 +1,21 @@ {lib, ...}: let inherit (lib) mkRemovedOptionModule; - inherit (lib.options) mkEnableOption; - inherit (lib.nvim.types) mkPluginSetupOption; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) enum; in { imports = [ (mkRemovedOptionModule ["vim" "autopairs" "nvim-compe"] "nvim-compe is deprecated and no longer suported.") ]; - options.vim.autopairs.nvim-autopairs = { - enable = mkEnableOption "autopairs"; - setupOpts = mkPluginSetupOption "nvim-autopairs" {}; + options.vim = { + autopairs = { + enable = mkEnableOption "autopairs" // {default = false;}; + + type = mkOption { + type = enum ["nvim-autopairs"]; + default = "nvim-autopairs"; + description = "Set the autopairs type. Options: nvim-autopairs [nvim-autopairs]"; + }; + }; }; } diff --git a/modules/plugins/completion/nvim-cmp/config.nix b/modules/plugins/completion/nvim-cmp/config.nix index ffd15fe4..a28db3ed 100644 --- a/modules/plugins/completion/nvim-cmp/config.nix +++ b/modules/plugins/completion/nvim-cmp/config.nix @@ -3,115 +3,246 @@ config, ... }: let - inherit (lib.modules) mkIf; - inherit (lib.strings) optionalString; - inherit (lib.generators) mkLuaInline; - inherit (lib.nvim.binds) addDescriptionsToMappings; - inherit (lib.nvim.dag) entryAfter; - inherit (lib.nvim.lua) toLuaObject; - inherit (builtins) attrNames; + inherit (builtins) toJSON; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.attrsets) attrNames mapAttrsToList; + inherit (lib.strings) concatMapStringsSep concatStringsSep optionalString; + inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding; + inherit (lib.nvim.dag) entryAnywhere entryAfter; - cfg = config.vim.autocomplete.nvim-cmp; - luasnipEnable = config.vim.snippets.luasnip.enable; + cfg = config.vim.autocomplete; + lspkindEnabled = config.vim.lsp.enable && config.vim.lsp.lspkind.enable; + + self = import ./nvim-cmp.nix {inherit lib;}; + mappingDefinitions = self.options.vim.autocomplete.mappings; - self = import ./nvim-cmp.nix {inherit lib config;}; - mappingDefinitions = self.options.vim.autocomplete.nvim-cmp.mappings; mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; + + builtSources = + concatMapStringsSep + "\n" + (n: "{ name = '${n}'},") + (attrNames cfg.sources); + + builtMaps = + concatStringsSep + "\n" + (mapAttrsToList + (n: v: + if v == null + then "" + else "${n} = '${v}',") + cfg.sources); + + dagPlacement = + if lspkindEnabled + then entryAfter ["lspkind"] + else entryAnywhere; in { config = mkIf cfg.enable { - vim = { - startPlugins = [ - "nvim-cmp" - "cmp-buffer" - "cmp-path" - ]; + vim.startPlugins = [ + "nvim-cmp" + "cmp-buffer" + "cmp-vsnip" + "cmp-path" + "vim-vsnip" + ]; - autocomplete.nvim-cmp.sources = { - nvim-cmp = null; - buffer = "[Buffer]"; - path = "[Path]"; - }; - - autocomplete.nvim-cmp.setupOpts = { - sources = map (s: {name = s;}) (attrNames cfg.sources); - - # TODO: try to get nvim-cmp to follow global border style - window = mkIf config.vim.ui.borders.enable { - completion = mkLuaInline "cmp.config.window.bordered()"; - documentation = mkLuaInline "cmp.config.window.bordered()"; - }; - - formatting.format = cfg.format; - }; - - pluginRC.nvim-cmp = mkIf cfg.enable (entryAfter ["autopairs" "luasnip"] '' - local luasnip = require("luasnip") - local cmp = require("cmp") - cmp.setup(${toLuaObject cfg.setupOpts}) - ''); - - # `cmp` and `luasnip` are defined above, in the `nvim-cmp` section - autocomplete.nvim-cmp.setupOpts.mapping = { - ${mappings.complete.value} = mkLuaInline "cmp.mapping.complete()"; - ${mappings.close.value} = mkLuaInline "cmp.mapping.abort()"; - ${mappings.scrollDocsUp.value} = mkLuaInline "cmp.mapping.scroll_docs(-4)"; - ${mappings.scrollDocsDown.value} = mkLuaInline "cmp.mapping.scroll_docs(4)"; - - ${mappings.confirm.value} = mkLuaInline '' - cmp.mapping(function(fallback) - if cmp.visible() then - ${ - if luasnipEnable - then '' - if luasnip.expandable() then - luasnip.expand() - else - cmp.confirm({ select = true }) - end - '' - else "cmp.confirm({ select = true })" - } - else - fallback() - end - end) - ''; - - ${mappings.next.value} = mkLuaInline '' - cmp.mapping(function(fallback) - local has_words_before = function() - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - end - - if cmp.visible() then - cmp.select_next_item() - ${optionalString luasnipEnable '' - elseif luasnip.locally_jumpable(1) then - luasnip.jump(1) - ''} - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end) - ''; - - ${mappings.previous.value} = mkLuaInline '' - cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - ${optionalString luasnipEnable '' - elseif luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - ''} - else - fallback() - end - end) - ''; - }; + vim.autocomplete.sources = { + "nvim-cmp" = null; + "vsnip" = "[VSnip]"; + "buffer" = "[Buffer]"; + "crates" = "[Crates]"; + "path" = "[Path]"; + "copilot" = "[Copilot]"; }; + + vim.maps.insert = mkMerge [ + (mkSetLuaBinding mappings.complete '' + require('cmp').complete + '') + (let + defaultKeys = + if config.vim.autopairs.enable + then "require('nvim-autopairs').autopairs_cr()" + else "vim.api.nvim_replace_termcodes(${toJSON mappings.confirm.value}, true, false, true)"; + in + mkSetLuaBinding mappings.confirm '' + function() + if not require('cmp').confirm({ select = true }) then + vim.fn.feedkeys(${defaultKeys}, 'n') + end + end + '') + (mkSetLuaBinding mappings.next '' + function() + local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + + local cmp = require('cmp') + + local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) + end + + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn['vsnip#available'](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.next.value}, true, false, true) + + vim.fn.feedkeys(termcode, 'n') + end + end + '') + (mkSetLuaBinding mappings.previous '' + function() + local cmp = require('cmp') + + local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) + end + + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn['vsnip#available'](-1) == 1 then + feedkeys("(vsnip-jump-prev)", "") + end + end + '') + (mkSetLuaBinding mappings.close '' + require('cmp').mapping.abort() + '') + (mkSetLuaBinding mappings.scrollDocsUp '' + require('cmp').mapping.scroll_docs(-4) + '') + (mkSetLuaBinding mappings.scrollDocsDown '' + require('cmp').mapping.scroll_docs(4) + '') + ]; + + vim.maps.command = mkMerge [ + (mkSetLuaBinding mappings.complete '' + require('cmp').complete + '') + (mkSetLuaBinding mappings.close '' + require('cmp').mapping.close() + '') + (mkSetLuaBinding mappings.scrollDocsUp '' + require('cmp').mapping.scroll_docs(-4) + '') + (mkSetLuaBinding mappings.scrollDocsDown '' + require('cmp').mapping.scroll_docs(4) + '') + ]; + + vim.maps.select = mkMerge [ + (mkSetLuaBinding mappings.next '' + function() + local cmp = require('cmp') + local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + + local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) + end + + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn['vsnip#available'](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.next.value}, true, false, true) + + vim.fn.feedkeys(termcode, 'n') + end + end + '') + (mkSetLuaBinding mappings.previous '' + function() + local cmp = require('cmp') + + local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) + end + + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn['vsnip#available'](-1) == 1 then + feedkeys("(vsnip-jump-prev)", "") + end + end + '') + ]; + + # TODO: alternative snippet engines to vsnip + # https://github.com/hrsh7th/nvim-cmp/blob/main/doc/cmp.txt#L82 + vim.pluginRC.completion = mkIf (cfg.type == "nvim-cmp") (dagPlacement '' + local nvim_cmp_menu_map = function(entry, vim_item) + -- name for each source + vim_item.menu = ({ + ${builtMaps} + })[entry.source.name] + return vim_item + end + + ${optionalString lspkindEnabled '' + lspkind_opts.before = ${cfg.formatting.format} + ''} + + local cmp = require'cmp' + cmp.setup({ + ${optionalString config.vim.ui.borders.enable '' + -- explicitly enabled by setting ui.borders.enable = true + -- TODO: try to get nvim-cmp to follow global border style + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + ''} + + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + + sources = { + ${builtSources} + }, + + completion = { + completeopt = 'menu,menuone,noinsert', + ${optionalString (!cfg.alwaysComplete) "autocomplete = false"} + }, + + formatting = { + format = + ${ + if lspkindEnabled + then "lspkind.cmp_format(lspkind_opts)" + else cfg.formatting.format + }, + } + }) + ${optionalString (config.vim.autopairs.enable && config.vim.autopairs.type == "nvim-autopairs") '' + local cmp_autopairs = require('nvim-autopairs.completion.cmp') + cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done({ map_char = { text = ""} })) + ''} + ''); + + vim.snippets.vsnip.enable = + if (cfg.type == "nvim-cmp") + then true + else config.vim.snippets.vsnip.enable; }; } diff --git a/modules/plugins/completion/nvim-cmp/default.nix b/modules/plugins/completion/nvim-cmp/default.nix index 65578c38..603347f4 100644 --- a/modules/plugins/completion/nvim-cmp/default.nix +++ b/modules/plugins/completion/nvim-cmp/default.nix @@ -1,4 +1,4 @@ -{ +_: { imports = [ ./config.nix ./nvim-cmp.nix diff --git a/modules/plugins/completion/nvim-cmp/nvim-cmp.nix b/modules/plugins/completion/nvim-cmp/nvim-cmp.nix index 860a1c3f..8efa649f 100644 --- a/modules/plugins/completion/nvim-cmp/nvim-cmp.nix +++ b/modules/plugins/completion/nvim-cmp/nvim-cmp.nix @@ -1,103 +1,72 @@ -{ - lib, - config, - ... -}: let - inherit (lib.options) mkEnableOption mkOption literalExpression literalMD; - inherit (lib.types) str attrsOf nullOr either; - inherit (lib.generators) mkLuaInline; +{lib, ...}: let + inherit (lib.options) mkEnableOption mkOption literalMD; inherit (lib.nvim.binds) mkMappingOption; - inherit (lib.nvim.types) mkPluginSetupOption luaInline mergelessListOf; - inherit (lib.nvim.lua) toLuaObject; - inherit (builtins) isString; - - cfg = config.vim.autocomplete.nvim-cmp; + inherit (lib.types) enum attrsOf nullOr str bool; in { - options.vim.autocomplete.nvim-cmp = { - enable = mkEnableOption "nvim-cmp"; - setupOpts = mkPluginSetupOption "the autocomplete plugin" { - completion.completeopt = mkOption { - type = str; - default = "menu,menuone,noinsert"; - description = '' - A comma-separated list of options for completion. + options.vim = { + autocomplete = { + enable = mkEnableOption "autocomplete" // {default = false;}; - See `:help completeopt` for the complete list. + alwaysComplete = mkOption { + type = bool; + description = "Automatically show completion."; + default = true; + }; + + mappings = { + complete = mkMappingOption "Complete [nvim-cmp]" ""; + confirm = mkMappingOption "Confirm [nvim-cmp]" ""; + next = mkMappingOption "Next item [nvim-cmp]" ""; + previous = mkMappingOption "Previous item [nvim-cmp]" ""; + close = mkMappingOption "Close [nvim-cmp]" ""; + scrollDocsUp = mkMappingOption "Scroll docs up [nvim-cmp]" ""; + scrollDocsDown = mkMappingOption "Scroll docs down [nvim-cmp]" ""; + }; + + type = mkOption { + type = enum ["nvim-cmp"]; + default = "nvim-cmp"; + description = "Set the autocomplete plugin. Options: [nvim-cmp]"; + }; + + sources = mkOption { + description = '' + Attribute set of source names for nvim-cmp. + + If an attribute set is provided, then the menu value of + `vim_item` in the format will be set to the value (if + utilizing the `nvim_cmp_menu_map` function). + + Note: only use a single attribute name per attribute set + ''; + type = attrsOf (nullOr str); + default = {}; + example = '' + {nvim-cmp = null; buffer = "[Buffer]";} ''; }; - sorting.comparators = mkOption { - type = mergelessListOf (either str luaInline); - default = [ - "offset" - "exact" - "score" - "kind" - "length" - "sort_text" - ]; - description = '' - The comparator functions used for sorting completions. + formatting = { + format = mkOption { + description = '' + The function used to customize the appearance of the completion menu. - You can either pass a valid inline lua function - (see `:help cmp-config.sorting.comparators`), - or a string, in which case the builtin comparator with that name will - be used. - ''; - apply = map ( - c: - if isString c - then mkLuaInline ("cmp.config.compare." + c) - else c - ); + If [](#opt-vim.lsp.lspkind.enable) is true, then the function + will be called before modifications from lspkind. + + Default is to call the menu mapping function. + ''; + type = str; + default = "nvim_cmp_menu_map"; + example = literalMD '' + ```lua + function(entry, vim_item) + return vim_item + end + ``` + ''; + }; }; }; - - mappings = { - complete = mkMappingOption "Complete [nvim-cmp]" ""; - confirm = mkMappingOption "Confirm [nvim-cmp]" ""; - next = mkMappingOption "Next item [nvim-cmp]" ""; - previous = mkMappingOption "Previous item [nvim-cmp]" ""; - close = mkMappingOption "Close [nvim-cmp]" ""; - scrollDocsUp = mkMappingOption "Scroll docs up [nvim-cmp]" ""; - scrollDocsDown = mkMappingOption "Scroll docs down [nvim-cmp]" ""; - }; - - format = mkOption { - type = luaInline; - default = mkLuaInline '' - function(entry, vim_item) - vim_item.menu = (${toLuaObject cfg.sources})[entry.source.name] - return vim_item - end - ''; - defaultText = literalMD '' - ```lua - function(entry, vim_item) - vim_item.menu = (''${toLuaObject config.vim.autocomplete.nvim-cmp.sources})[entry.source.name] - return vim_item - end - ``` - ''; - description = '' - The function used to customize the completion menu entires. This is - outside of `setupOpts` to allow for an easier integration with - lspkind.nvim. - - See `:help cmp-config.formatting.format`. - ''; - }; - - sources = mkOption { - type = attrsOf (nullOr str); - default = {}; - description = "The list of sources used by nvim-cmp"; - example = literalExpression '' - { - nvim-cmp = null; - buffer = "[Buffer]"; - } - ''; - }; }; } diff --git a/modules/plugins/debugger/nvim-dap/config.nix b/modules/plugins/debugger/nvim-dap/config.nix index 358d7c86..072ad9af 100644 --- a/modules/plugins/debugger/nvim-dap/config.nix +++ b/modules/plugins/debugger/nvim-dap/config.nix @@ -16,61 +16,57 @@ in { config = mkMerge [ (mkIf cfg.enable { - vim = { - startPlugins = ["nvim-dap"]; + vim.startPlugins = ["nvim-dap"]; - pluginRC = - { - # TODO customizable keymaps - nvim-dap = entryAnywhere '' - local dap = require("dap") - vim.fn.sign_define("DapBreakpoint", { text = "🛑", texthl = "ErrorMsg", linehl = "", numhl = "" }) - ''; - } - // mapAttrs (_: v: (entryAfter ["nvim-dap"] v)) cfg.sources; + vim.pluginRC = + { + # TODO customizable keymaps + nvim-dap = entryAnywhere '' + local dap = require("dap") + vim.fn.sign_define("DapBreakpoint", { text = "🛑", texthl = "ErrorMsg", linehl = "", numhl = "" }) + ''; + } + // mapAttrs (_: v: (entryAfter ["nvim-dap"] v)) cfg.sources; - maps.normal = mkMerge [ - (mkSetLuaBinding mappings.continue "require('dap').continue") - (mkSetLuaBinding mappings.restart "require('dap').restart") - (mkSetLuaBinding mappings.terminate "require('dap').terminate") - (mkSetLuaBinding mappings.runLast "require('dap').run_last") + vim.maps.normal = mkMerge [ + (mkSetLuaBinding mappings.continue "require('dap').continue") + (mkSetLuaBinding mappings.restart "require('dap').restart") + (mkSetLuaBinding mappings.terminate "require('dap').terminate") + (mkSetLuaBinding mappings.runLast "require('dap').run_last") - (mkSetLuaBinding mappings.toggleRepl "require('dap').repl.toggle") - (mkSetLuaBinding mappings.hover "require('dap.ui.widgets').hover") - (mkSetLuaBinding mappings.toggleBreakpoint "require('dap').toggle_breakpoint") + (mkSetLuaBinding mappings.toggleRepl "require('dap').repl.toggle") + (mkSetLuaBinding mappings.hover "require('dap.ui.widgets').hover") + (mkSetLuaBinding mappings.toggleBreakpoint "require('dap').toggle_breakpoint") - (mkSetLuaBinding mappings.runToCursor "require('dap').run_to_cursor") - (mkSetLuaBinding mappings.stepInto "require('dap').step_into") - (mkSetLuaBinding mappings.stepOut "require('dap').step_out") - (mkSetLuaBinding mappings.stepOver "require('dap').step_over") - (mkSetLuaBinding mappings.stepBack "require('dap').step_back") + (mkSetLuaBinding mappings.runToCursor "require('dap').run_to_cursor") + (mkSetLuaBinding mappings.stepInto "require('dap').step_into") + (mkSetLuaBinding mappings.stepOut "require('dap').step_out") + (mkSetLuaBinding mappings.stepOver "require('dap').step_over") + (mkSetLuaBinding mappings.stepBack "require('dap').step_back") - (mkSetLuaBinding mappings.goUp "require('dap').up") - (mkSetLuaBinding mappings.goDown "require('dap').down") - ]; - }; + (mkSetLuaBinding mappings.goUp "require('dap').up") + (mkSetLuaBinding mappings.goDown "require('dap').down") + ]; }) (mkIf (cfg.enable && cfg.ui.enable) { - vim = { - startPlugins = ["nvim-dap-ui" "nvim-nio"]; + vim.startPlugins = ["nvim-dap-ui" "nvim-nio"]; - pluginRC.nvim-dap-ui = entryAfter ["nvim-dap"] ('' - local dapui = require("dapui") - dapui.setup() - '' - + optionalString cfg.ui.autoStart '' - dap.listeners.after.event_initialized["dapui_config"] = function() - dapui.open() - end - dap.listeners.before.event_terminated["dapui_config"] = function() - dapui.close() - end - dap.listeners.before.event_exited["dapui_config"] = function() - dapui.close() - end - ''); - maps.normal = mkSetLuaBinding mappings.toggleDapUI "require('dapui').toggle"; - }; + vim.pluginRC.nvim-dap-ui = entryAfter ["nvim-dap"] ('' + local dapui = require("dapui") + dapui.setup() + '' + + optionalString cfg.ui.autoStart '' + dap.listeners.after.event_initialized["dapui_config"] = function() + dapui.open() + end + dap.listeners.before.event_terminated["dapui_config"] = function() + dapui.close() + end + dap.listeners.before.event_exited["dapui_config"] = function() + dapui.close() + end + ''); + vim.maps.normal = mkSetLuaBinding mappings.toggleDapUI "require('dapui').toggle"; }) ]; } diff --git a/modules/plugins/languages/default.nix b/modules/plugins/languages/default.nix index 54a9e1c4..28c1fd8f 100644 --- a/modules/plugins/languages/default.nix +++ b/modules/plugins/languages/default.nix @@ -8,7 +8,6 @@ in { ./css.nix ./elixir.nix ./go.nix - ./kotlin.nix ./html.nix ./java.nix ./lua.nix @@ -20,7 +19,6 @@ in { ./python.nix ./r.nix ./rust.nix - ./scala.nix ./sql.nix ./svelte.nix ./tailwind.nix diff --git a/modules/plugins/languages/kotlin.nix b/modules/plugins/languages/kotlin.nix deleted file mode 100644 index 5637b4f4..00000000 --- a/modules/plugins/languages/kotlin.nix +++ /dev/null @@ -1,107 +0,0 @@ -{ - config, - pkgs, - lib, - ... -}: let - inherit (lib.options) mkEnableOption mkOption literalExpression; - inherit (lib.modules) mkIf mkMerge; - inherit (lib.meta) getExe; - inherit (lib.nvim.languages) diagnosticsToLua; - inherit (lib.types) package; - inherit (lib.nvim.types) mkGrammarOption diagnostics; - inherit (lib.lists) isList; - inherit (lib.nvim.lua) expToLua; - - cfg = config.vim.languages.kotlin; - - defaultDiagnosticsProvider = ["ktlint"]; - diagnosticsProviders = { - ktlint = { - package = pkgs.ktlint; - nullConfig = pkg: '' - table.insert( - ls_sources, - null_ls.builtins.diagnostics.ktlint.with({ - command = "${getExe pkg}", - }) - ) - ''; - }; - }; -in { - options.vim.languages.kotlin = { - enable = mkEnableOption "Kotlin/HCL support"; - - treesitter = { - enable = mkEnableOption "Kotlin treesitter" // {default = config.vim.languages.enableTreesitter;}; - package = mkGrammarOption pkgs "kotlin"; - }; - - lsp = { - enable = mkEnableOption "Kotlin LSP support" // {default = config.vim.languages.enableLSP;}; - - package = mkOption { - description = "kotlin_language_server package with Kotlin runtime"; - type = package; - example = literalExpression '' - pkgs.symlinkJoin { - name = "kotlin-language-server-wrapped"; - paths = [pkgs.kotlin-language-server]; - nativeBuildInputs = [pkgs.makeWrapper]; - postBuild = ''' - wrapProgram $out/bin/kotlin-language-server \ - --prefix PATH : ''${pkgs.kotlin}/bin - '''; - }; - ''; - default = pkgs.kotlin-language-server; - }; - }; - - extraDiagnostics = { - enable = mkEnableOption "extra Kotlin diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;}; - - types = diagnostics { - langDesc = "Kotlin"; - inherit diagnosticsProviders; - inherit defaultDiagnosticsProvider; - }; - }; - }; - config = mkIf cfg.enable (mkMerge [ - (mkIf cfg.treesitter.enable { - vim.treesitter.enable = true; - vim.treesitter.grammars = [cfg.treesitter.package]; - }) - - (mkIf cfg.extraDiagnostics.enable { - vim.lsp.null-ls.enable = true; - vim.lsp.null-ls.sources = diagnosticsToLua { - lang = "kotlin"; - config = cfg.extraDiagnostics.types; - inherit diagnosticsProviders; - }; - }) - - (mkIf cfg.lsp.enable { - vim.lsp.lspconfig.enable = true; - vim.lsp.lspconfig.sources.kotlin_language_server = '' - lspconfig.kotlin_language_server.setup { - capabilities = capabilities, - root_dir = lspconfig.util.root_pattern("main.kt", ".git"), - on_attach=default_on_attach, - init_options = { - -- speeds up the startup time for the LSP - storagePath = vim.fn.stdpath('state') .. '/kotlin', - }, - cmd = ${ - if isList cfg.lsp.package - then expToLua cfg.lsp.package - else ''{"${cfg.lsp.package}/bin/kotlin-language-server"}'' - }, - } - ''; - }) - ]); -} diff --git a/modules/plugins/languages/rust.nix b/modules/plugins/languages/rust.nix index 9a388896..0f595761 100644 --- a/modules/plugins/languages/rust.nix +++ b/modules/plugins/languages/rust.nix @@ -9,7 +9,7 @@ inherit (lib.options) mkOption mkEnableOption; inherit (lib.strings) optionalString; inherit (lib.trivial) boolToString; - inherit (lib.lists) isList; + inherit (lib.lists) isList optionals; inherit (lib.types) bool package str listOf either enum; inherit (lib.nvim.types) mkGrammarOption; inherit (lib.nvim.lua) expToLua; @@ -101,7 +101,7 @@ in { vim = { startPlugins = ["crates-nvim"]; lsp.null-ls.enable = mkIf cfg.crates.codeActions true; - autocomplete.nvim-cmp.sources = {crates = "[Crates]";}; + autocomplete.sources = {"crates" = "[Crates]";}; pluginRC.rust-crates = entryAnywhere '' require('crates').setup { null_ls = { diff --git a/modules/plugins/languages/scala.nix b/modules/plugins/languages/scala.nix deleted file mode 100644 index f769d092..00000000 --- a/modules/plugins/languages/scala.nix +++ /dev/null @@ -1,149 +0,0 @@ -{ - config, - pkgs, - lib, - ... -}: let - inherit (lib.generators) mkLuaInline; - inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.binds) mkMappingOption; - inherit (lib.nvim.dag) entryAfter; - inherit (lib.nvim.lua) toLuaObject; - inherit (lib.nvim.types) mkGrammarOption luaInline; - inherit (lib.options) mkOption mkEnableOption mkPackageOption; - inherit (lib.strings) optionalString; - inherit (lib.types) attrsOf anything bool; - - listCommandsAction = - if config.vim.telescope.enable - then ''require("telescope").extensions.metals.commands()'' - else ''require("metals").commands()''; - - cfg = config.vim.languages.scala; - - usingDap = config.vim.debugger.nvim-dap.enable && cfg.dap.enable; - usingLualine = config.vim.statusline.lualine.enable; -in { - options.vim.languages.scala = { - enable = mkEnableOption "Scala language support"; - - treesitter = { - enable = mkEnableOption "Scala treesitter" // {default = config.vim.languages.enableTreesitter;}; - package = mkGrammarOption pkgs "scala"; - }; - - lsp = { - enable = mkEnableOption "Scala LSP support (metals)" // {default = config.vim.languages.enableLSP;}; - package = mkPackageOption pkgs "metals" { - default = ["metals"]; - }; - - extraMappings = { - listCommands = mkMappingOption "List Metals commands" "lc"; - }; - - extraSettings = mkOption { - type = attrsOf anything; - description = "Extra settings passed to the metals config. Check nvim-metals docs for available options"; - default = { - showImplicitArguments = true; - showImplicitConversionsAndClasses = true; - showInferredType = true; - excludedPackages = [ - "akka.actor.typed.javadsl" - "com.github.swagger.akka.javadsl" - ]; - }; - }; - }; - - dap = { - enable = mkEnableOption "Scala Debug Adapter support (metals)" // {default = config.vim.languages.enableDAP;}; - config = mkOption { - description = "Lua configuration for dap"; - type = luaInline; - default = mkLuaInline '' - dap.configurations.scala = { - { - type = "scala", - request = "launch", - name = "RunOrTest", - metals = { - runType = "runOrTestFile", - --args = { "firstArg", "secondArg", "thirdArg" }, -- here just as an example - }, - }, - { - type = "scala", - request = "launch", - name = "Test Target", - metals = { - runType = "testTarget", - }, - }, - } - ''; - }; - }; - - fixShortmess = mkOption { - type = bool; - description = "Remove the 'F' flag from shortmess to allow messages to be shown. Without doing this, autocommands that deal with filetypes prohibit messages from being shown"; - default = true; - }; - }; - - config = mkIf cfg.enable ( - mkMerge [ - (mkIf cfg.treesitter.enable { - vim.treesitter.enable = true; - vim.treesitter.grammars = [cfg.treesitter.package]; - }) - (mkIf (cfg.lsp.enable || cfg.dap.enable) { - vim = { - startPlugins = ["nvim-metals"]; - pluginRC.nvim-metals = entryAfter ["lsp-setup"] '' - local metals_caps = capabilities -- from lsp-setup - - local attach_metals_keymaps = function(client, bufnr) - attach_keymaps(client, bufnr) -- from lsp-setup - vim.api.nvim_buf_set_keymap(bufnr, 'n', '${cfg.lsp.extraMappings.listCommands}', 'lua ${listCommandsAction}', {noremap=true, silent=true, desc='Show all Metals commands'}) - end - - metals_config = require('metals').bare_config() - ${optionalString usingLualine "metals_config.init_options.statusBarProvider = 'on'"} - - metals_config.capabilities = metals_caps - metals_config.on_attach = function(client, bufnr) - ${optionalString usingDap "require('metals').setup_dap()"} - attach_metals_keymaps(client, bufnr) - end - - metals_config.settings = ${toLuaObject cfg.lsp.extraSettings} - metals_config.settings.metalsBinaryPath = "${cfg.lsp.package}/bin/metals" - - metals_config.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( - vim.lsp.diagnostic.on_publish_diagnostics, { - virtual_text = { - prefix = '⚠', - } - } - ) - - ${optionalString cfg.fixShortmess ''vim.opt_global.shortmess:remove("F")''} - - local lsp_group = vim.api.nvim_create_augroup('lsp', { clear = true }) - - vim.api.nvim_create_autocmd('FileType', { - group = lsp_group, - pattern = {'java', 'scala', 'sbt'}, - callback = function() - require('metals').initialize_or_attach(metals_config) - end, - }) - ''; - }; - }) - ] - ); -} diff --git a/modules/plugins/lsp/config.nix b/modules/plugins/lsp/config.nix index 52dc15b4..a0aa7fee 100644 --- a/modules/plugins/lsp/config.nix +++ b/modules/plugins/lsp/config.nix @@ -11,7 +11,7 @@ inherit (lib.nvim.binds) addDescriptionsToMappings; cfg = config.vim.lsp; - usingNvimCmp = config.vim.autocomplete.nvim-cmp.enable; + usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp"; self = import ./module.nix {inherit config lib pkgs;}; mappingDefinitions = self.options.vim.lsp.mappings; @@ -25,7 +25,7 @@ in { vim = { startPlugins = optional usingNvimCmp "cmp-nvim-lsp"; - autocomplete.nvim-cmp.sources = {nvim_lsp = "[LSP]";}; + autocomplete.sources = {"nvim_lsp" = "[LSP]";}; pluginRC.lsp-setup = '' vim.g.formatsave = ${boolToString cfg.formatOnSave}; diff --git a/modules/plugins/lsp/lspkind/config.nix b/modules/plugins/lsp/lspkind/config.nix index 2ef20ff8..93426e0c 100644 --- a/modules/plugins/lsp/lspkind/config.nix +++ b/modules/plugins/lsp/lspkind/config.nix @@ -3,32 +3,18 @@ lib, ... }: let - inherit (lib.modules) mkIf mkForce; - inherit (lib.generators) mkLuaInline; - inherit (lib.nvim.lua) toLuaObject; + inherit (lib.modules) mkIf; + inherit (lib.nvim.dag) entryAnywhere; - cfg = config.vim.lsp.lspkind; + cfg = config.vim.lsp; in { - config = mkIf cfg.enable { - assertions = [ - { - assertion = config.vim.autocomplete.nvim-cmp.enable; - message = '' - While lspkind supports Neovim's native lsp upstream, using that over - nvim-cmp isn't recommended, nor supported by nvf. - - Please migrate to nvim-cmp if you want to use lspkind. - ''; + config = mkIf (cfg.enable && cfg.lspkind.enable) { + vim.startPlugins = ["lspkind"]; + vim.pluginRC.lspkind = entryAnywhere '' + local lspkind = require'lspkind' + local lspkind_opts = { + mode = '${cfg.lspkind.mode}' } - ]; - - vim = { - startPlugins = ["lspkind"]; - - lsp.lspkind.setupOpts.before = config.vim.autocomplete.nvim-cmp.format; - autocomplete.nvim-cmp.setupOpts.formatting.format = mkForce (mkLuaInline '' - require("lspkind").cmp_format(${toLuaObject cfg.setupOpts}) - ''); - }; + ''; }; } diff --git a/modules/plugins/lsp/lspkind/lspkind.nix b/modules/plugins/lsp/lspkind/lspkind.nix index 595decd7..8ae9f39a 100644 --- a/modules/plugins/lsp/lspkind/lspkind.nix +++ b/modules/plugins/lsp/lspkind/lspkind.nix @@ -1,22 +1,16 @@ {lib, ...}: let inherit (lib.options) mkEnableOption mkOption; - inherit (lib.types) enum nullOr; - inherit (lib.nvim.types) mkPluginSetupOption luaInline; + inherit (lib.types) enum; in { - options.vim.lsp.lspkind = { - enable = mkEnableOption "vscode-like pictograms for lsp [lspkind]"; - setupOpts = mkPluginSetupOption "lspkind.nvim" { + options.vim.lsp = { + lspkind = { + enable = mkEnableOption "vscode-like pictograms for lsp [lspkind]"; + mode = mkOption { description = "Defines how annotations are shown"; type = enum ["text" "text_symbol" "symbol_text" "symbol"]; default = "symbol_text"; }; - - before = mkOption { - description = "The function that will be called before lspkind's modifications are applied"; - type = nullOr luaInline; - default = null; - }; }; }; } diff --git a/modules/plugins/notes/neorg/config.nix b/modules/plugins/notes/neorg/config.nix index 54a6bd8c..367f2567 100644 --- a/modules/plugins/notes/neorg/config.nix +++ b/modules/plugins/notes/neorg/config.nix @@ -34,6 +34,8 @@ in { } (mkIf cfg.treesitter.enable { + vim.treesitter.enable = true; + vim.treesitter.grammars = [cfg.treesitter.norgPackage]; }) ]); diff --git a/modules/plugins/notes/neorg/neorg.nix b/modules/plugins/notes/neorg/neorg.nix index eae7a3c1..f6ab8aec 100644 --- a/modules/plugins/notes/neorg/neorg.nix +++ b/modules/plugins/notes/neorg/neorg.nix @@ -9,9 +9,7 @@ inherit (lib.nvim.types) mkGrammarOption mkPluginSetupOption; in { options.vim.notes.neorg = { - enable = mkEnableOption '' - Neorg: An intuitive note-taking and organization tool with a structured nested syntax. - ''; + enable = mkEnableOption "neorg: Neovim plugin for Neorg"; setupOpts = mkPluginSetupOption "Neorg" { load = { @@ -20,7 +18,7 @@ in { type = submodule { options = { - enable = mkEnableOption "Wrapper to interface with several different completion engines."; + enable = mkEnableOption "A wrapper to interface with several different completion engines."; config = { disable = mkOption { type = listOf str; diff --git a/modules/plugins/notes/obsidian/obsidian.nix b/modules/plugins/notes/obsidian/obsidian.nix index 2dae5a9c..6727430a 100644 --- a/modules/plugins/notes/obsidian/obsidian.nix +++ b/modules/plugins/notes/obsidian/obsidian.nix @@ -45,10 +45,10 @@ in { completion = { nvim_cmp = mkOption { - # If using nvim-cmp, otherwise set to false + # if using nvim-cmp, otherwise set to false type = bool; description = "If using nvim-cmp, otherwise set to false"; - default = config.vim.autocomplete.nvim-cmp.enable; + default = config.vim.autocomplete.type == "nvim-cmp"; }; }; }; diff --git a/modules/plugins/snippets/default.nix b/modules/plugins/snippets/default.nix index 1b97343f..3f9758a1 100644 --- a/modules/plugins/snippets/default.nix +++ b/modules/plugins/snippets/default.nix @@ -1,5 +1,5 @@ { imports = [ - ./luasnip + ./vsnip ]; } diff --git a/modules/plugins/snippets/luasnip/config.nix b/modules/plugins/snippets/luasnip/config.nix deleted file mode 100644 index 541fd0fd..00000000 --- a/modules/plugins/snippets/luasnip/config.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ - config, - lib, - ... -}: let - inherit (lib.modules) mkIf; - - cfg = config.vim.snippets.luasnip; -in { - config = mkIf cfg.enable { - vim = { - startPlugins = ["luasnip" "cmp-luasnip"] ++ cfg.providers; - autocomplete.nvim-cmp.sources = {luasnip = "[LuaSnip]";}; - pluginRC.luasnip = cfg.loaders; - }; - }; -} diff --git a/modules/plugins/snippets/luasnip/default.nix b/modules/plugins/snippets/luasnip/default.nix deleted file mode 100644 index f7e94d38..00000000 --- a/modules/plugins/snippets/luasnip/default.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - imports = [ - ./luasnip.nix - ./config.nix - ]; -} diff --git a/modules/plugins/snippets/luasnip/luasnip.nix b/modules/plugins/snippets/luasnip/luasnip.nix deleted file mode 100644 index d9563a5b..00000000 --- a/modules/plugins/snippets/luasnip/luasnip.nix +++ /dev/null @@ -1,36 +0,0 @@ -{lib, ...}: let - inherit (lib.options) mkEnableOption mkOption literalExpression literalMD; - inherit (lib.types) listOf lines; - inherit (lib.nvim.types) pluginType; -in { - options.vim.snippets.luasnip = { - enable = mkEnableOption "luasnip"; - providers = mkOption { - type = listOf pluginType; - default = ["friendly-snippets"]; - description = '' - The snippet provider packages. - - ::: {.note} - These are simply appended to {option} `vim.startPlugins`. - ::: - ''; - example = literalExpression "[\"vimPlugins.vim-snippets\"]"; - }; - loaders = mkOption { - type = lines; - default = "require('luasnip.loaders.from_vscode').lazy_load()"; - defaultText = literalMD '' - ```lua - require('luasnip.loaders.from_vscode').lazy_load() - ``` - ''; - description = "Lua code used to load snippet providers."; - example = literalMD '' - ```lua - require("luasnip.loaders.from_snipmate").lazy_load() - ``` - ''; - }; - }; -} diff --git a/modules/plugins/snippets/vsnip/config.nix b/modules/plugins/snippets/vsnip/config.nix new file mode 100644 index 00000000..5c6ba75f --- /dev/null +++ b/modules/plugins/snippets/vsnip/config.nix @@ -0,0 +1,13 @@ +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkIf; + + cfg = config.vim.snippets.vsnip; +in { + config = mkIf cfg.enable { + vim.startPlugins = ["vim-vsnip"]; + }; +} diff --git a/modules/plugins/snippets/vsnip/default.nix b/modules/plugins/snippets/vsnip/default.nix new file mode 100644 index 00000000..87ef29e0 --- /dev/null +++ b/modules/plugins/snippets/vsnip/default.nix @@ -0,0 +1,5 @@ +{ + imports = [ + ./vsnip.nix + ]; +} diff --git a/modules/plugins/snippets/vsnip/vsnip.nix b/modules/plugins/snippets/vsnip/vsnip.nix new file mode 100644 index 00000000..5d3b6d97 --- /dev/null +++ b/modules/plugins/snippets/vsnip/vsnip.nix @@ -0,0 +1,7 @@ +{lib, ...}: let + inherit (lib.options) mkEnableOption; +in { + options.vim.snippets.vsnip = { + enable = mkEnableOption "vim-vsnip: snippet LSP/VSCode's format"; + }; +} diff --git a/modules/plugins/theme/theme.nix b/modules/plugins/theme/theme.nix index 0422c027..95d15d40 100644 --- a/modules/plugins/theme/theme.nix +++ b/modules/plugins/theme/theme.nix @@ -4,11 +4,10 @@ ... }: let inherit (lib.options) mkOption; - inherit (lib.attrsets) attrNames; + inherit (lib.attrsets) attrNames listToAttrs; inherit (lib.strings) hasPrefix; inherit (lib.types) bool lines enum; inherit (lib.modules) mkIf; - inherit (lib.nvim.attrsets) mapListToAttrs; inherit (lib.nvim.dag) entryBefore; inherit (lib.nvim.types) hexColor; @@ -18,8 +17,7 @@ }; numbers = ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F"]; - base16Options = - mapListToAttrs (n: { + base16Options = listToAttrs (map (n: { name = "base0${n}"; value = mkOption { description = "The base0${n} color to use"; @@ -30,7 +28,7 @@ else "#${v}"; }; }) - numbers; + numbers); in { options.vim.theme = { enable = mkOption { diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index ae093862..618da88e 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -11,7 +11,7 @@ inherit (lib.nvim.dag) entryBefore entryAfter; cfg = config.vim.treesitter; - usingNvimCmp = config.vim.autocomplete.nvim-cmp.enable; + usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp"; self = import ./treesitter.nix {inherit pkgs lib;}; mappingDefinitions = self.options.vim.treesitter.mappings; @@ -21,7 +21,7 @@ in { vim = { startPlugins = ["nvim-treesitter"] ++ optional usingNvimCmp "cmp-treesitter"; - autocomplete.nvim-cmp.sources = {treesitter = "[Treesitter]";}; + autocomplete.sources = {"treesitter" = "[Treesitter]";}; treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars; maps = { diff --git a/modules/plugins/ui/noice/noice.nix b/modules/plugins/ui/noice/noice.nix index edd80ee1..bf16e3f1 100644 --- a/modules/plugins/ui/noice/noice.nix +++ b/modules/plugins/ui/noice/noice.nix @@ -21,7 +21,7 @@ in { mkBool true "override the lsp markdown formatter with Noice"; "cmp.entry.get_documentation" = - mkBool config.vim.autocomplete.nvim-cmp.enable "override cmp documentation with Noice"; + mkBool (config.vim.autocomplete.type == "nvim-cmp") "override cmp documentation with Noice"; }; signature = { diff --git a/modules/plugins/utility/motion/leap/config.nix b/modules/plugins/utility/motion/leap/config.nix index 687ed24d..9ede98f3 100644 --- a/modules/plugins/utility/motion/leap/config.nix +++ b/modules/plugins/utility/motion/leap/config.nix @@ -3,7 +3,7 @@ lib, ... }: let - inherit (lib.modules) mkIf mkMerge mkDefault; + inherit (lib.modules) mkIf mkMerge; inherit (lib.nvim.binds) mkBinding; inherit (lib.nvim.dag) entryAnywhere; @@ -37,8 +37,6 @@ in { (mkBinding cfg.mappings.leapFromWindow "(leap-from-window)" "Leap from window") ]; - vim.binds.whichKey.register."s" = mkDefault "+Leap"; - vim.pluginRC.leap-nvim = entryAnywhere '' require('leap').opts = { max_phase_one_targets = nil, diff --git a/modules/plugins/utility/motion/leap/leap.nix b/modules/plugins/utility/motion/leap/leap.nix index 4e98f208..a5d72432 100644 --- a/modules/plugins/utility/motion/leap/leap.nix +++ b/modules/plugins/utility/motion/leap/leap.nix @@ -9,22 +9,22 @@ in { leapForwardTo = mkOption { type = nullOr str; description = "Leap forward to"; - default = "ss"; + default = "s"; }; leapBackwardTo = mkOption { type = nullOr str; description = "Leap backward to"; - default = "sS"; + default = "S"; }; leapForwardTill = mkOption { type = nullOr str; description = "Leap forward till"; - default = "sx"; + default = "x"; }; leapBackwardTill = mkOption { type = nullOr str; description = "Leap backward till"; - default = "sX"; + default = "X"; }; leapFromWindow = mkOption { type = nullOr str; diff --git a/modules/wrapper/rc/config.nix b/modules/wrapper/rc/config.nix index 6cc1e4e9..6f9ed1ce 100644 --- a/modules/wrapper/rc/config.nix +++ b/modules/wrapper/rc/config.nix @@ -4,7 +4,7 @@ ... }: let inherit (builtins) map mapAttrs filter; - inherit (lib.attrsets) mapAttrsToList; + inherit (lib.attrsets) mapAttrsToList filterAttrs; inherit (lib.strings) concatLines concatMapStringsSep; inherit (lib.trivial) showWarnings; inherit (lib.generators) mkLuaInline; diff --git a/modules/wrapper/rc/options.nix b/modules/wrapper/rc/options.nix index 1159b9fe..70ab2a8a 100644 --- a/modules/wrapper/rc/options.nix +++ b/modules/wrapper/rc/options.nix @@ -3,18 +3,27 @@ lib, ... }: let + inherit (lib.modules) mkRemovedOptionModule; inherit (lib.options) mkOption mkEnableOption literalMD literalExpression; inherit (lib.strings) optionalString; - inherit (lib.types) str attrs lines listOf either path; + inherit (lib.types) str attrs lines listOf either path bool; inherit (lib.nvim.types) dagOf; inherit (lib.nvim.lua) listToLuaTable; cfg = config.vim; in { + imports = [ + (mkRemovedOptionModule ["vim" "configRC"] '' + Please migrate your configRC sections to Neovim's Lua format, and + add them to luaConfigRC. + + See the v0.7 release notes for more information on how to migrate + your existing configurations. + '') + ]; + options.vim = { enableLuaLoader = mkEnableOption '' - [{option}`official documentation`]: https://neovim.io/doc/user/lua.html#vim.loader.enable() - the experimental Lua module loader to speed up the start up process If `true`, this will enable the experimental Lua module loader which: @@ -23,12 +32,30 @@ in { - adds the libs loader - removes the default Neovim loader - ::: {.note} This is disabled by default. Before setting this option, please - take a look at the [{option}`official documentation`]. - ::: + take a look at the [{option}`official documentation`](https://neovim.io/doc/user/lua.html#vim.loader.enable()). ''; + disableDefaultRuntimePaths = mkOption { + type = bool; + default = true; + example = false; + description = '' + Disables the default runtime paths that are set by Neovim + when it starts up. This is useful when you want to have + full control over the runtime paths that are set by Neovim. + + ::: {.note} + To avoid leaking imperative user configuration into your + configuration, this is enabled by default. If you wish + to load configuration from user configuration directories + (e.g. {file}`$HOME/.config/nvim`, {file}`$HOME/.config/nvim/after` + and {file}`$HOME/.local/share/nvim/site`) you may set this + option to true. + ::: + ''; + }; + additionalRuntimePaths = mkOption { type = listOf (either path str); default = []; @@ -153,6 +180,21 @@ in { vim.opt.runtimepath:append(${listToLuaTable cfg.additionalRuntimePaths}) ''} + ${optionalString cfg.disableDefaultRuntimePaths '' + -- Remove default user runtime paths from the + -- `runtimepath` option to avoid leaking user configuration + -- into the final neovim wrapper + local defaultRuntimePaths = { + vim.fn.stdpath('config'), -- $HOME/.config/nvim + vim.fn.stdpath('config') .. "/after", -- $HOME/.config/nvim/after + vim.fn.stdpath('data') .. "/site", -- $HOME/.local/share/nvim/site + } + + for _, path in ipairs(defaultRuntimePaths) do + vim.opt.runtimepath:remove(path) + end + ''} + ${optionalString cfg.enableLuaLoader "vim.loader.enable()"} '';