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;
}