diff --git a/docs/manual/configuring/custom-plugins.md b/docs/manual/configuring/custom-plugins.md index 76b32ea4..c58c4973 100644 --- a/docs/manual/configuring/custom-plugins.md +++ b/docs/manual/configuring/custom-plugins.md @@ -20,7 +20,6 @@ custom plugins that you might have added to your configuration. ```{=include=} sections custom-plugins/configuring.md -custom-plugins/lazy-method.md -custom-plugins/non-lazy-method.md -custom-plugins/legacy-method.md +custom-plugins/new-method.md +custom-plugins/old-method.md ``` diff --git a/docs/manual/configuring/custom-plugins/configuring.md b/docs/manual/configuring/custom-plugins/configuring.md index 71ce9b8f..5e837ce1 100644 --- a/docs/manual/configuring/custom-plugins/configuring.md +++ b/docs/manual/configuring/custom-plugins/configuring.md @@ -1,32 +1,12 @@ # Configuring {#sec-configuring-plugins} -Just making the plugin to your Neovim configuration available might not always be enough. In that -case, you can write custom lua config using either `config.vim.lazy.plugins.*.setupOpts` -`config.vim.extraPlugins.*.setup` or `config.vim.luaConfigRC`. - -The first option uses an extended version of `lz.n`'s PluginSpec. `setupModule` and `setupOpt` can -be used if the plugin uses a `require('module').setup(...)` pattern. Otherwise, the `before` and -`after` hooks should do what you need. - -```nix -{ - config.vim.lazy.plugins = { - aerial-nvim = { - # ^^^^^^^^^ this name should match the package.pname or package.name - package = aerial-nvim; - - setupModule = "aerial"; - setupOpts = {option_name = false;}; - - after = "print('aerial loaded')"; - }; - }; -} -``` - -The second option uses an attribute set, which maps DAG section names to a custom type, which has -the fields `package`, `after`, `setup`. They allow you to set the package of the plugin, the -sections its setup code should be after (note that the `extraPlugins` option has its own DAG +Just making the plugin to your Neovim configuration available might not always +be enough. In that case, you can write custom lua config using either +`config.vim.extraPlugins` (which has the `setup` field) or +`config.vim.luaConfigRC`. The first option uses an attribute set, which maps DAG +section names to a custom type, which has the fields `package`, `after`, +`setup`. They allow you to set the package of the plugin, the sections its setup +code should be after (note that the `extraPlugins` option has its own DAG scope), and the its setup code respectively. For example: ```nix @@ -44,7 +24,7 @@ config.vim.extraPlugins = with pkgs.vimPlugins; { } ``` -The third option also uses an attribute set, but this one is resolved as a DAG +The second option also uses an attribute set, but this one is resolved as a DAG directly. The attribute names denote the section names, and the values lua code. For example: diff --git a/docs/manual/configuring/custom-plugins/lazy-method.md b/docs/manual/configuring/custom-plugins/lazy-method.md deleted file mode 100644 index 77b77d5d..00000000 --- a/docs/manual/configuring/custom-plugins/lazy-method.md +++ /dev/null @@ -1,40 +0,0 @@ -# Lazy Method {#sec-lazy-method} - -As of version **0.7**, we exposed an API for configuring lazy-loaded plugins via -`lz.n` and `lzn-auto-require`. - -```nix -{ - config.vim.lazy.plugins = { - aerial = { - package = pkgs.vimPlugins.aerial-nvim; - setupModule = aerial; - setupOpts = { - option_name = true; - }; - after = '' - -- custom lua code to run after plugin is loaded - print('aerial loaded') - ''; - - # Explicitly mark plugin as lazy. You don't need this if you define one of - # the trigger "events" below - lazy = true; - - # load on command - cmd = ["AerialOpen"]; - - # load on event - event = ["BufEnter"]; - - # load on keymap - keys = [ - { - key = "a"; - action = ":AerialToggle"; - } - ]; - }; - }; -} -``` diff --git a/docs/manual/configuring/custom-plugins/non-lazy-method.md b/docs/manual/configuring/custom-plugins/new-method.md similarity index 93% rename from docs/manual/configuring/custom-plugins/non-lazy-method.md rename to docs/manual/configuring/custom-plugins/new-method.md index 351af2eb..200ba5e7 100644 --- a/docs/manual/configuring/custom-plugins/non-lazy-method.md +++ b/docs/manual/configuring/custom-plugins/new-method.md @@ -1,4 +1,4 @@ -# Non-lazy Method {#sec-non-lazy-method} +# New Method {#sec-new-method} As of version **0.5**, we have a more extensive API for configuring plugins, under `vim.extraPlugins`. Instead of using DAGs exposed by the library, you may diff --git a/docs/manual/configuring/custom-plugins/legacy-method.md b/docs/manual/configuring/custom-plugins/old-method.md similarity index 96% rename from docs/manual/configuring/custom-plugins/legacy-method.md rename to docs/manual/configuring/custom-plugins/old-method.md index 0a6b3775..3b9d090e 100644 --- a/docs/manual/configuring/custom-plugins/legacy-method.md +++ b/docs/manual/configuring/custom-plugins/old-method.md @@ -1,4 +1,4 @@ -# Legacy Method {#sec-legacy-method} +# Old Method {#sec-old-method} Prior to version 0.5, the method of adding new plugins was adding the plugin package to `vim.startPlugins` and add its configuration as a DAG under one of diff --git a/docs/manual/configuring/dag-entries.md b/docs/manual/configuring/dag-entries.md index ff5d5c72..32dd4c6e 100644 --- a/docs/manual/configuring/dag-entries.md +++ b/docs/manual/configuring/dag-entries.md @@ -12,9 +12,9 @@ entries in nvf: 2. `globalsScript` - used to set globals defined in `vim.globals` 3. `basic` - used to set basic configuration options 4. `optionsScript` - used to set options defined in `vim.o` -5. `theme` (this is simply placed before `pluginConfigs` and `lazyConfigs`, meaning that - surrounding entries don't depend on it) - used to set up the theme, which has to be done before - other plugins +5. `theme` (this is simply placed before `pluginConfigs`, meaning that + surrounding entries don't depend on it) - used to set up the theme, which has + to be done before other plugins 6. `lazyConfigs` - `lz.n` and `lzn-auto-require` configs. If `vim.lazy.enable` is false, this will contain each plugin's config instead. 7. `pluginConfigs` - the result of the nested `vim.pluginRC` (internal option, diff --git a/modules/plugins/comments/comment-nvim/config.nix b/modules/plugins/comments/comment-nvim/config.nix index c2c1a7e2..0fde7885 100644 --- a/modules/plugins/comments/comment-nvim/config.nix +++ b/modules/plugins/comments/comment-nvim/config.nix @@ -11,6 +11,8 @@ inherit (self.options.vim.comments.comment-nvim) mappings; in { config = mkIf cfg.enable { + vim.startPlugins = ["comment-nvim"]; + vim.lazy.plugins.comment-nvim = { package = "comment-nvim"; setupModule = "Comment"; diff --git a/modules/plugins/completion/nvim-cmp/config.nix b/modules/plugins/completion/nvim-cmp/config.nix index 54670ace..27d0bfb6 100644 --- a/modules/plugins/completion/nvim-cmp/config.nix +++ b/modules/plugins/completion/nvim-cmp/config.nix @@ -41,13 +41,13 @@ in { package = "nvim-cmp"; after = '' ${optionalString luasnipEnable "local luasnip = require('luasnip')"} + require("lz.n").trigger_load("cmp-path") local cmp = require("cmp") cmp.setup(${toLuaObject cfg.setupOpts}) - ${optionalString config.vim.lazy.enable - (concatStringsSep "\n" (map - (package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})") - cfg.sourcePlugins))} + ${concatStringsSep "\n" (map + (package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})") + cfg.sourcePlugins)} ''; event = ["InsertEnter" "CmdlineEnter"]; @@ -74,50 +74,50 @@ in { }; formatting.format = cfg.format; + }; - # `cmp` and `luasnip` are defined above, in the `nvim-cmp` section - mapping = { - ${mappings.complete} = mkLuaInline "cmp.mapping.complete()"; - ${mappings.close} = mkLuaInline "cmp.mapping.abort()"; - ${mappings.scrollDocsUp} = mkLuaInline "cmp.mapping.scroll_docs(-4)"; - ${mappings.scrollDocsDown} = mkLuaInline "cmp.mapping.scroll_docs(4)"; - ${mappings.confirm} = mkLuaInline "cmp.mapping.confirm({ select = true })"; + # `cmp` and `luasnip` are defined above, in the `nvim-cmp` section + setupOpts.mapping = { + ${mappings.complete} = mkLuaInline "cmp.mapping.complete()"; + ${mappings.close} = mkLuaInline "cmp.mapping.abort()"; + ${mappings.scrollDocsUp} = mkLuaInline "cmp.mapping.scroll_docs(-4)"; + ${mappings.scrollDocsDown} = mkLuaInline "cmp.mapping.scroll_docs(4)"; + ${mappings.confirm} = mkLuaInline "cmp.mapping.confirm({ select = true })"; - ${mappings.next} = 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 + ${mappings.next} = 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) - ''; + 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} = 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) - ''; - }; + ${mappings.previous} = 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) + ''; }; }; }; diff --git a/modules/plugins/lsp/config.nix b/modules/plugins/lsp/config.nix index 29949340..841e28bb 100644 --- a/modules/plugins/lsp/config.nix +++ b/modules/plugins/lsp/config.nix @@ -116,60 +116,7 @@ in { end local capabilities = vim.lsp.protocol.make_client_capabilities() - ${optionalString usingNvimCmp '' - -- HACK: copied from cmp-nvim-lsp. If we ever lazy load lspconfig we - -- should re-evaluate whether we can just use `default_capabilities` - capabilities = { - textDocument = { - completion = { - dynamicRegistration = false, - completionItem = { - snippetSupport = true, - commitCharactersSupport = true, - deprecatedSupport = true, - preselectSupport = true, - tagSupport = { - valueSet = { - 1, -- Deprecated - } - }, - insertReplaceSupport = true, - resolveSupport = { - properties = { - "documentation", - "detail", - "additionalTextEdits", - "sortText", - "filterText", - "insertText", - "textEdit", - "insertTextFormat", - "insertTextMode", - }, - }, - insertTextModeSupport = { - valueSet = { - 1, -- asIs - 2, -- adjustIndentation - } - }, - labelDetailsSupport = true, - }, - contextSupport = true, - insertTextMode = 1, - completionList = { - itemDefaults = { - 'commitCharacters', - 'editRange', - 'insertTextFormat', - 'insertTextMode', - 'data', - } - } - }, - }, - } - ''} + -- ${optionalString usingNvimCmp "capabilities = require('cmp_nvim_lsp').default_capabilities()"} ''; }; }; diff --git a/modules/plugins/theme/theme.nix b/modules/plugins/theme/theme.nix index b3147c00..0422c027 100644 --- a/modules/plugins/theme/theme.nix +++ b/modules/plugins/theme/theme.nix @@ -66,7 +66,7 @@ in { config = mkIf cfg.enable { vim = { startPlugins = [cfg.name]; - luaConfigRC.theme = entryBefore ["pluginConfigs" "lazyConfigs"] '' + luaConfigRC.theme = entryBefore ["pluginConfigs"] '' ${cfg.extraConfig} ${supportedThemes.${cfg.name}.setup {inherit (cfg) style transparent base16-colors;}} ''; diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index 566a716e..e863d048 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -11,6 +11,7 @@ inherit (lib.nvim.dag) entryBefore entryAfter; cfg = config.vim.treesitter; + usingNvimCmp = config.vim.autocomplete.nvim-cmp.enable; self = import ./treesitter.nix {inherit pkgs lib;}; mappingDefinitions = self.options.vim.treesitter.mappings; @@ -20,6 +21,17 @@ in { vim = { startPlugins = ["nvim-treesitter"]; + lazy.plugins = { + cmp-treesitter = mkIf usingNvimCmp { + package = "cmp-treesitter"; + after = '' + local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/cmp-treesitter') + require("rtp_nvim").source_after_plugin_dir(path) + ''; + }; + nvim-cmp.after = mkIf usingNvimCmp "require('lz.n').trigger_load('cmp-treesitter')"; + }; + autocomplete.nvim-cmp = { sources = {treesitter = "[Treesitter]";}; sourcePlugins = ["cmp-treesitter"];