diff --git a/plugins/completion/cmp/cmp-helpers.nix b/plugins/completion/cmp/cmp-helpers.nix index 93010f94..a40af0be 100644 --- a/plugins/completion/cmp/cmp-helpers.nix +++ b/plugins/completion/cmp/cmp-helpers.nix @@ -20,52 +20,6 @@ with lib; rec { maintainers = [maintainers.GaetanLepage]; }; - pluginAndSourceNames = { - "buffer" = "cmp-buffer"; - "calc" = "cmp-calc"; - "dap" = "cmp-dap"; - "cmdline" = "cmp-cmdline"; - "cmp-clippy" = "cmp-clippy"; - "cmp-cmdline-history" = "cmp-cmdline-history"; - "cmp_pandoc" = "cmp-pandoc-nvim"; - "cmp_tabby" = "cmp-tabby"; - "cmp_tabnine" = "cmp-tabnine"; - "codeium" = "codeium-nvim"; - "conventionalcommits" = "cmp-conventionalcommits"; - "copilot" = "copilot-cmp"; - "crates" = "crates-nvim"; - "dictionary" = "cmp-dictionary"; - "digraphs" = "cmp-digraphs"; - "emoji" = "cmp-emoji"; - "fish" = "cmp-fish"; - "fuzzy_buffer" = "cmp-fuzzy-buffer"; - "fuzzy_path" = "cmp-fuzzy-path"; - "git" = "cmp-git"; - "greek" = "cmp-greek"; - "latex_symbols" = "cmp-latex-symbols"; - "look" = "cmp-look"; - "luasnip" = "cmp_luasnip"; - "nvim_lsp" = "cmp-nvim-lsp"; - "nvim_lsp_document_symbol" = "cmp-nvim-lsp-document-symbol"; - "nvim_lsp_signature_help" = "cmp-nvim-lsp-signature-help"; - "nvim_lua" = "cmp-nvim-lua"; - "npm" = "cmp-npm"; - "omni" = "cmp-omni"; - "pandoc_references" = "cmp-pandoc-references"; - "path" = "cmp-path"; - "rg" = "cmp-rg"; - "snippy" = "cmp-snippy"; - "spell" = "cmp-spell"; - "tmux" = "cmp-tmux"; - "treesitter" = "cmp-treesitter"; - "ultisnips" = "cmp-nvim-ultisnips"; - "vim_lsp" = "cmp-vim-lsp"; - "vimwiki-tags" = "cmp-vimwiki-tags"; - "vsnip" = "cmp-vsnip"; - "yanky" = "cmp_yanky"; - "zsh" = "cmp-zsh"; - }; - extractSourcesFromOptionValue = sources: if isList sources then sources @@ -100,16 +54,24 @@ with lib; rec { allSources ); - # A list of known source names - knownSourceNames = attrNames pluginAndSourceNames; - attrsEnabled = listToAttrs (map - (name: { - # Name of the corresponding plugin to enable - name = pluginAndSourceNames.${name}; - # Whether or not we enable it - value.enable = mkIf (elem name foundSources) true; - }) - knownSourceNames); + # If the user has enabled the `foo` and `bar` sources, this attrs will look like: + # { + # cmp-foo.enable = true; + # cmp-bar.enable = true; + # } + attrsEnabled = + mapAttrs' + ( + sourceName: pluginName: { + name = pluginName; + value.enable = + mkIf + (elem sourceName foundSources) + true; + } + ) + (import ./sources.nix); + lspCapabilities = mkIf (elem "nvim_lsp" foundSources) diff --git a/plugins/completion/cmp/sources.nix b/plugins/completion/cmp/sources.nix new file mode 100644 index 00000000..fc40d3fa --- /dev/null +++ b/plugins/completion/cmp/sources.nix @@ -0,0 +1,46 @@ +# Maps each source name to the plugin that provides it +{ + buffer = "cmp-buffer"; + calc = "cmp-calc"; + dap = "cmp-dap"; + cmdline = "cmp-cmdline"; + cmp-clippy = "cmp-clippy"; + cmp-cmdline-history = "cmp-cmdline-history"; + cmp_pandoc = "cmp-pandoc-nvim"; + cmp_tabby = "cmp-tabby"; + cmp_tabnine = "cmp-tabnine"; + codeium = "codeium-nvim"; + conventionalcommits = "cmp-conventionalcommits"; + copilot = "copilot-cmp"; + crates = "crates-nvim"; + dictionary = "cmp-dictionary"; + digraphs = "cmp-digraphs"; + emoji = "cmp-emoji"; + fish = "cmp-fish"; + fuzzy_buffer = "cmp-fuzzy-buffer"; + fuzzy_path = "cmp-fuzzy-path"; + git = "cmp-git"; + greek = "cmp-greek"; + latex_symbols = "cmp-latex-symbols"; + look = "cmp-look"; + luasnip = "cmp_luasnip"; + nvim_lsp = "cmp-nvim-lsp"; + nvim_lsp_document_symbol = "cmp-nvim-lsp-document-symbol"; + nvim_lsp_signature_help = "cmp-nvim-lsp-signature-help"; + nvim_lua = "cmp-nvim-lua"; + npm = "cmp-npm"; + omni = "cmp-omni"; + pandoc_references = "cmp-pandoc-references"; + path = "cmp-path"; + rg = "cmp-rg"; + snippy = "cmp-snippy"; + spell = "cmp-spell"; + tmux = "cmp-tmux"; + treesitter = "cmp-treesitter"; + ultisnips = "cmp-nvim-ultisnips"; + vim_lsp = "cmp-vim-lsp"; + vimwiki-tags = "cmp-vimwiki-tags"; + vsnip = "cmp-vsnip"; + yanky = "cmp_yanky"; + zsh = "cmp-zsh"; +} diff --git a/plugins/completion/cmp/sources/default.nix b/plugins/completion/cmp/sources/default.nix index fd1302a6..959891f1 100644 --- a/plugins/completion/cmp/sources/default.nix +++ b/plugins/completion/cmp/sources/default.nix @@ -7,7 +7,7 @@ }: with lib; let cmpLib = import ../cmp-helpers.nix {inherit lib config helpers pkgs;}; - cmpSourcesPluginNames = attrValues cmpLib.pluginAndSourceNames; + cmpSourcesPluginNames = attrValues (import ../sources.nix); pluginModules = map (