From addc78bea024c85860d60d9682a1ed2664fdf2f6 Mon Sep 17 00:00:00 2001 From: t4ccer <64430288+t4ccer@users.noreply.github.com> Date: Mon, 26 Jul 2021 04:40:07 +0200 Subject: [PATCH] neovim: Add coc support (#2154) This adds two new options: 'programs.neovim.coc.{enable,settings}`. These settings offer a simple interface over `xdg.configFile."nvim/coc-settings.json`, using the standard Nix' syntax instead of a multiline string. --- modules/programs/neovim.nix | 51 +++++++++++++++++-- .../programs/neovim/coc-config.expected | 3 ++ tests/modules/programs/neovim/coc-config.nix | 27 ++++++++++ tests/modules/programs/neovim/default.nix | 1 + 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 tests/modules/programs/neovim/coc-config.expected create mode 100644 tests/modules/programs/neovim/coc-config.nix diff --git a/modules/programs/neovim.nix b/modules/programs/neovim.nix index 8cb93bf36..64e8f94ba 100644 --- a/modules/programs/neovim.nix +++ b/modules/programs/neovim.nix @@ -6,6 +6,8 @@ let cfg = config.programs.neovim; + jsonFormat = pkgs.formats.json { }; + extraPython3PackageType = mkOptionType { name = "extra-python3-packages"; description = "python3 packages in python.withPackages format"; @@ -217,6 +219,44 @@ in { This option is mutually exclusive with configure. ''; }; + + coc = { + enable = mkEnableOption "Coc"; + + settings = mkOption { + type = jsonFormat.type; + default = { }; + example = literalExample '' + { + "suggest.noselect" = true; + "suggest.enablePreview" = true; + "suggest.enablePreselect" = false; + "suggest.disableKind" = true; + languageserver = { + haskell = { + command = "haskell-language-server-wrapper"; + args = [ "--lsp" ]; + rootPatterns = [ + "*.cabal" + "stack.yaml" + "cabal.project" + "package.yaml" + "hie.yaml" + ]; + filetypes = [ "haskell" "lhaskell" ]; + }; + }; + }; + ''; + description = '' + Extra configuration lines to add to + $XDG_CONFIG_HOME/nvim/coc-settings.json + See + + for options. + ''; + }; + }; }; }; @@ -225,7 +265,8 @@ in { inherit (cfg) extraPython3Packages withPython3 withNodeJs withRuby viAlias vimAlias; configure = cfg.configure // moduleConfigure; - plugins = cfg.plugins; + plugins = cfg.plugins + ++ optionals cfg.coc.enable [ pkgs.vimPlugins.coc-nvim ]; customRC = cfg.extraConfig; }; @@ -241,9 +282,13 @@ in { home.packages = [ cfg.finalPackage ]; - xdg.configFile = mkIf (neovimConfig.neovimRcContent != "") { - "nvim/init.vim".text = neovimConfig.neovimRcContent; + xdg.configFile."nvim/init.vim" = mkIf (neovimConfig.neovimRcContent != "") { + text = neovimConfig.neovimRcContent; }; + xdg.configFile."nvim/coc-settings.json" = mkIf cfg.coc.enable { + source = jsonFormat.generate "coc-settings.json" cfg.coc.settings; + }; + programs.neovim.finalPackage = pkgs.wrapNeovimUnstable cfg.package (neovimConfig // { wrapperArgs = (lib.escapeShellArgs neovimConfig.wrapperArgs) + " " diff --git a/tests/modules/programs/neovim/coc-config.expected b/tests/modules/programs/neovim/coc-config.expected new file mode 100644 index 000000000..c8c4105eb --- /dev/null +++ b/tests/modules/programs/neovim/coc-config.expected @@ -0,0 +1,3 @@ +{ + "foo": "bar" +} diff --git a/tests/modules/programs/neovim/coc-config.nix b/tests/modules/programs/neovim/coc-config.nix new file mode 100644 index 000000000..c16514134 --- /dev/null +++ b/tests/modules/programs/neovim/coc-config.nix @@ -0,0 +1,27 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.neovim = { + enable = true; + coc = { + enable = true; + settings = { + # my variable + foo = "bar"; + }; + }; + }; + + nmt.script = '' + cocSettings="$TESTED/home-files/.config/nvim/coc-settings.json" + cocSettingsNormalized="$(normalizeStorePaths "$cocSettings")" + + assertFileExists "$cocSettings" + assertFileContent "$cocSettingsNormalized" "${./coc-config.expected}" + ''; + }; +} + diff --git a/tests/modules/programs/neovim/default.nix b/tests/modules/programs/neovim/default.nix index 13efac9b6..8a6c316ea 100644 --- a/tests/modules/programs/neovim/default.nix +++ b/tests/modules/programs/neovim/default.nix @@ -1,5 +1,6 @@ { neovim-plugin-config = ./plugin-config.nix; + neovim-coc-config = ./coc-config.nix; # waiting for a nixpkgs patch # neovim-no-init = ./no-init.nix; }