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.
This commit is contained in:
t4ccer 2021-07-26 04:40:07 +02:00 committed by GitHub
parent 0423a7b40c
commit addc78bea0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 79 additions and 3 deletions

View File

@ -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 <varname>configure</varname>.
'';
};
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
<filename>$XDG_CONFIG_HOME/nvim/coc-settings.json</filename>
See
<link xlink:href="https://github.com/neoclide/coc.nvim/wiki/Using-the-configuration-file" />
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) + " "

View File

@ -0,0 +1,3 @@
{
"foo": "bar"
}

View File

@ -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}"
'';
};
}

View File

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