From 1057ef93e3f072b93d7a6d3b7235e0b6c7364366 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Mon, 1 Jan 2024 21:50:06 +0100 Subject: [PATCH] plugins/codeium-nvim: init --- plugins/completion/nvim-cmp/cmp-helpers.nix | 1 + .../nvim-cmp/sources/codeium-nvim.nix | 89 +++++++++++++++++++ .../completion/nvim-cmp/sources/default.nix | 1 + .../plugins/completion/codeium-nvim.nix | 36 ++++++++ 4 files changed, 127 insertions(+) create mode 100644 plugins/completion/nvim-cmp/sources/codeium-nvim.nix create mode 100644 tests/test-sources/plugins/completion/codeium-nvim.nix diff --git a/plugins/completion/nvim-cmp/cmp-helpers.nix b/plugins/completion/nvim-cmp/cmp-helpers.nix index b4a6ff6bda..2d19d23ac5 100644 --- a/plugins/completion/nvim-cmp/cmp-helpers.nix +++ b/plugins/completion/nvim-cmp/cmp-helpers.nix @@ -61,5 +61,6 @@ in "cmp_pandoc" = "cmp-pandoc-nvim"; "treesitter" = "cmp-treesitter"; "vimwiki-tags" = "cmp-vimwiki-tags"; + "codeium" = "codeium-nvim"; }; } diff --git a/plugins/completion/nvim-cmp/sources/codeium-nvim.nix b/plugins/completion/nvim-cmp/sources/codeium-nvim.nix new file mode 100644 index 0000000000..8b98ba811d --- /dev/null +++ b/plugins/completion/nvim-cmp/sources/codeium-nvim.nix @@ -0,0 +1,89 @@ +{ + lib, + helpers, + config, + pkgs, + ... +}: +with lib; let + cfg = config.plugins.codeium-nvim; +in { + meta.maintainers = [maintainers.GaetanLepage]; + + options.plugins.codeium-nvim = + helpers.extraOptionsOptions + // { + package = helpers.mkPackageOption "codeium.nvim" pkgs.vimPlugins.codeium-nvim; + + configPath = + helpers.defaultNullOpts.mkStr + ''{__raw = "vim.fn.stdpath('cache') .. '/codeium/config.json'";}'' + "The path to the config file, used to store the API key."; + + binPath = + helpers.defaultNullOpts.mkStr + ''{__raw = "vim.fn.stdpath('cache') .. '/codeium/bin'";}'' + "The path to the directory where the Codeium server will be downloaded to."; + + api = { + host = helpers.defaultNullOpts.mkStr "server.codeium.com" '' + The hostname of the API server to use. + ''; + + port = helpers.defaultNullOpts.mkPositiveInt 443 '' + The port of the API server to use. + ''; + }; + + tools = { + uname = helpers.mkNullOrOption types.str "The path to the `uname` binary."; + + uuidgen = helpers.mkNullOrOption types.str "The path to the `uuidgen` binary."; + + curl = helpers.mkNullOrOption types.str "The path to the `curl` binary."; + + gzip = helpers.mkNullOrOption types.str "The path to the `gzip` binary."; + + languageServer = helpers.mkNullOrOption types.str '' + The path to the language server downloaded from the official source. + ''; + }; + + wrapper = helpers.mkNullOrOption types.str '' + The path to a wrapper script/binary that is used to execute any binaries not listed under + tools. + This is primarily useful for NixOS, where a FHS wrapper can be used for the downloaded + codeium server. + ''; + }; + + config = mkIf cfg.enable { + extraConfigLua = let + setupOptions = with cfg; + { + config_path = configPath; + bin_path = binPath; + api = with api; { + inherit host; + port = + if isInt port + then toString port + else port; + }; + tools = with tools; { + inherit + uname + uuidgen + curl + gzip + ; + language_server = languageServer; + }; + inherit wrapper; + } + // cfg.extraOptions; + in '' + require('codeium').setup(${helpers.toLuaObject setupOptions}) + ''; + }; +} diff --git a/plugins/completion/nvim-cmp/sources/default.nix b/plugins/completion/nvim-cmp/sources/default.nix index f89411b19a..04e9385f5d 100644 --- a/plugins/completion/nvim-cmp/sources/default.nix +++ b/plugins/completion/nvim-cmp/sources/default.nix @@ -12,6 +12,7 @@ in { # For extra cmp plugins imports = [ + ./codeium-nvim.nix ./copilot-cmp.nix ./cmp-tabnine.nix ./crates-nvim.nix diff --git a/tests/test-sources/plugins/completion/codeium-nvim.nix b/tests/test-sources/plugins/completion/codeium-nvim.nix new file mode 100644 index 0000000000..e6990ee98b --- /dev/null +++ b/tests/test-sources/plugins/completion/codeium-nvim.nix @@ -0,0 +1,36 @@ +{ + empty = { + plugins.codeium-nvim.enable = true; + }; + + enabled-by-cmp = { + plugins.nvim-cmp = { + enable = true; + + sources = [ + {name = "codeium";} + ]; + }; + }; + + defaults = { + plugins.codeium-nvim = { + enable = true; + + configPath.__raw = "vim.fn.stdpath('cache') .. '/codeium/config.json'"; + binPath.__raw = "vim.fn.stdpath('cache') .. '/codeium/bin'"; + api = { + host = "server.codeium.com"; + port = 443; + }; + tools = { + uname = null; + uuidgen = null; + curl = null; + gzip = null; + languageServer = null; + }; + wrapper = null; + }; + }; +}