Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins/coq: Switch to mkNeovimPlugin #1256

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 56 additions & 38 deletions plugins/completion/coq.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,74 @@
pkgs,
...
}:
with lib; let
cfg = config.plugins.coq-nvim;
in {
options = {
plugins.coq-nvim = {
enable = mkEnableOption "coq-nvim";
with lib;
helpers.neovim-plugin.mkNeovimPlugin config {
name = "coq-nvim";
originalName = "coq_nvim";
defaultPackage = pkgs.vimPlugins.coq_nvim;

package = helpers.mkPackageOption "coq-nvim" pkgs.vimPlugins.coq_nvim;
maintainers = [maintainers.traxys];

extraOptions = {
installArtifacts = mkEnableOption "and install coq-artifacts";

autoStart = mkOption {
type = with types; nullOr (oneOf [bool (enum ["shut-up"])]);
default = null;
description = "Auto-start or shut up";
artifactsPackage = mkOption {
type = types.package;
description = "Package to use for coq-artifacts (when enabled with installArtifacts)";
default = pkgs.vimPlugins.coq-artifacts;
};
};

recommendedKeymaps = mkOption {
type = with types; nullOr bool;
default = null;
description = "Use the recommended keymaps";
};
# TODO: Introduced 12-03-2022, remove 12-05-2022
optionsRenamedToSettings = [
"xdg"
"autoStart"
];
imports = let
basePath = ["plugins" "coq-nvim"];
settingsPath = basePath ++ ["settings"];
in [
(
mkRenamedOptionModule
(basePath ++ ["recommendedKeymaps"])
(settingsPath ++ ["keymap" "recommended"])
)

(
mkRenamedOptionModule
(basePath ++ ["alwaysComplete"])
(settingsPath ++ ["completion" "always"])
)
];

callSetup = false;
settingsOptions = {
auto_start =
helpers.mkNullOrOption
(with helpers.nixvimTypes; maybeRaw (either bool (enum ["shut-up"])))
"Auto-start or shut up";

alwaysComplete = mkOption {
type = with types; nullOr bool;
default = null;
description = "Always trigger completion on keystroke";
xdg = mkOption {
type = types.bool;
default = true;
description = "Use XDG paths. May be required when installing coq with Nix.";
};

keymap.recommended = helpers.defaultNullOpts.mkBool true "Use the recommended keymaps";

completion.always = helpers.defaultNullOpts.mkBool true "Always trigger completion on keystroke";
};
};
config = let
settings = {
auto_start = cfg.autoStart;
"keymap.recommended" = cfg.recommendedKeymaps;
xdg = true;
"completion.always" = cfg.alwaysComplete;
};
in
mkIf cfg.enable {
extraPlugins =
[
cfg.package
]
++ optional cfg.installArtifacts pkgs.vimPlugins.coq-artifacts;

extraConfig = cfg: {
extraPlugins = mkIf cfg.installArtifacts [
cfg.artifactsPackage
];

plugins.lsp = {
preConfig = ''
vim.g.coq_settings = ${helpers.toLuaObject settings}
vim.g.coq_settings = ${helpers.toLuaObject cfg.settings}
local coq = require 'coq'
'';
setupWrappers = [(s: ''coq.lsp_ensure_capabilities(${s})'')];
};
};
}
}
25 changes: 25 additions & 0 deletions tests/test-sources/plugins/completion/coq.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
empty = {
plugins.coq-nvim.enable = true;
};

nixvim-defaults = {
plugins.coq-nvim = {
enable = true;

settings = {
xdg = true;
auto_start = true;
keymap.recommended = true;
completion.always = true;
};
};
};

artifacts = {
plugins.coq-nvim = {
enable = true;
installArtifacts = true;
};
};
}