From 7ae81019d92f6354878983d3eabbd3504d448ed5 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Thu, 22 Jun 2023 09:48:17 +0200 Subject: [PATCH] plugins/copilot: rename copilot -> copilot-vim --- plugins/completion/copilot-vim.nix | 65 +++++++++++++++++++ plugins/completion/copilot.nix | 46 ------------- plugins/default.nix | 2 +- plugins/languages/tagbar.nix | 2 +- .../plugins/completion/copilot-vim.nix | 18 +++++ 5 files changed, 85 insertions(+), 48 deletions(-) create mode 100644 plugins/completion/copilot-vim.nix delete mode 100644 plugins/completion/copilot.nix create mode 100644 tests/test-sources/plugins/completion/copilot-vim.nix diff --git a/plugins/completion/copilot-vim.nix b/plugins/completion/copilot-vim.nix new file mode 100644 index 00000000..63dab0a5 --- /dev/null +++ b/plugins/completion/copilot-vim.nix @@ -0,0 +1,65 @@ +{ + config, + pkgs, + lib, + ... +}: +with lib; let + cfg = config.plugins.copilot-vim; + helpers = import ../helpers.nix {inherit lib;}; +in { + imports = [ + (lib.mkRenamedOptionModule ["plugins" "copilot"] ["plugins" "copilot-vim"]) + ]; + + options = { + plugins.copilot-vim = { + enable = mkEnableOption "copilot.vim"; + + package = helpers.mkPackageOption "copilot.vim" pkgs.vimPlugins.copilot-vim; + + filetypes = mkOption { + type = types.attrsOf types.bool; + description = "A dictionary mapping file types to their enabled status"; + default = {}; + example = literalExpression '' + { + "*" = false; + python = true; + } + ''; + }; + + proxy = helpers.defaultNullOpts.mkStr "" '' + Tell Copilot what proxy server to use. + Example: "localhost:3128" + ''; + + extraConfig = mkOption { + type = types.attrs; + description = '' + The configuration options for copilot without the 'copilot_' prefix. + Example: To set 'copilot_foo_bar' to 1, write + extraConfig = { + foo_bar = true; + }; + ''; + default = {}; + }; + }; + }; + + config = mkIf cfg.enable { + extraPlugins = [cfg.package]; + + globals = with cfg; + mapAttrs' (name: nameValuePair ("copilot_" + name)) + ( + { + node_command = "${pkgs.nodejs-18_x}/bin/node"; + inherit filetypes proxy; + } + // cfg.extraConfig + ); + }; +} diff --git a/plugins/completion/copilot.nix b/plugins/completion/copilot.nix deleted file mode 100644 index 45dc0946..00000000 --- a/plugins/completion/copilot.nix +++ /dev/null @@ -1,46 +0,0 @@ -{ - config, - pkgs, - lib, - ... -}: -with lib; let - cfg = config.plugins.copilot; - helpers = import ../helpers.nix {inherit lib;}; -in { - options = { - plugins.copilot = { - enable = mkEnableOption "copilot"; - package = helpers.mkPackageOption "copilot" pkgs.vimPlugins.copilot-vim; - filetypes = mkOption { - type = types.attrsOf types.bool; - description = "A dictionary mapping file types to their enabled status"; - default = {}; - example = literalExpression '' { - "*": false, - python: true - }''; - }; - proxy = mkOption { - type = types.nullOr types.str; - description = "Tell Copilot what proxy server to use."; - default = null; - example = "localhost:3128"; - }; - }; - }; - - config = mkIf cfg.enable { - extraPlugins = [cfg.package]; - globals = - { - copilot_node_command = "${pkgs.nodejs-18_x}/bin/node"; - copilot_filetypes = cfg.filetypes; - } - // ( - if cfg.proxy != null - then {copilot_proxy = cfg.proxy;} - else {} - ); - }; -} diff --git a/plugins/default.nix b/plugins/default.nix index 94c72b02..4c88bde5 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -15,7 +15,7 @@ ./completion/coq.nix ./completion/coq-thirdparty.nix - ./completion/copilot.nix + ./completion/copilot-vim.nix ./completion/nvim-cmp ./completion/nvim-cmp/sources ./completion/lspkind.nix diff --git a/plugins/languages/tagbar.nix b/plugins/languages/tagbar.nix index a696957f..68431b28 100644 --- a/plugins/languages/tagbar.nix +++ b/plugins/languages/tagbar.nix @@ -17,7 +17,7 @@ in The configuration options for tagbar without the 'tagbar_' prefix. Example: To set 'tagbar_show_tag_count' to 1, write extraConfig = { - show_tag_count= true; + show_tag_count = true; }; ''; }; diff --git a/tests/test-sources/plugins/completion/copilot-vim.nix b/tests/test-sources/plugins/completion/copilot-vim.nix new file mode 100644 index 00000000..e7d3cfa6 --- /dev/null +++ b/tests/test-sources/plugins/completion/copilot-vim.nix @@ -0,0 +1,18 @@ +{ + empty = { + plugins.copilot-vim.enable = true; + }; + + example = { + plugins.copilot-vim = { + enable = true; + + filetypes = { + "*" = false; + python = true; + }; + + proxy = "localhost:3128"; + }; + }; +}