Merge pull request #99 from horriblename/feature/extra-plugins

This commit is contained in:
raf 2023-07-28 11:28:20 +03:00 committed by GitHub
commit f2f9c32eca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 8 deletions

View file

@ -4,6 +4,6 @@
typesLanguage = import ./languages.nix {inherit lib;}; typesLanguage = import ./languages.nix {inherit lib;};
in { in {
inherit (typesDag) dagOf; inherit (typesDag) dagOf;
inherit (typesPlugin) pluginsOpt; inherit (typesPlugin) pluginsOpt extraPluginType;
inherit (typesLanguage) diagnostics mkGrammarOption; inherit (typesLanguage) diagnostics mkGrammarOption;
} }

View file

@ -90,15 +90,37 @@ with lib; let
"copilot-cmp" "copilot-cmp"
]; ];
# You can either use the name of the plugin or a package. # You can either use the name of the plugin or a package.
pluginsType = with types; pluginType = with types;
listOf ( nullOr (
nullOr ( either
either package
(enum availablePlugins) (enum availablePlugins)
package
)
); );
pluginsType = types.listOf pluginType;
extraPluginType = with types;
submodule {
options = {
package = mkOption {
type = pluginType;
};
after = mkOption {
type = listOf str;
default = [];
description = "Setup this plugin after the following ones.";
};
setup = mkOption {
type = lines;
default = "";
description = "Lua code to run during setup.";
example = "require('aerial').setup {}";
};
};
};
in { in {
inherit extraPluginType;
pluginsOpt = { pluginsOpt = {
description, description,
default ? [], default ? [],

View file

@ -158,6 +158,27 @@ in {
description = "List of plugins to optionally load"; description = "List of plugins to optionally load";
}; };
extraPlugins = mkOption {
type = types.attrsOf nvim.types.extraPluginType;
default = {};
description = ''
List of plugins and related config.
Note that these are setup after builtin plugins.
'';
example = literalExpression ''
with pkgs.vimPlugins; {
aerial = {
package = aerial-nvim;
setup = "require('aerial').setup {}";
};
harpoon = {
package = harpoon;
setup = "require('harpoon').setup {}";
after = ["aerial"];
};
}'';
};
globals = mkOption { globals = mkOption {
default = {}; default = {};
description = "Set containing global variable values"; description = "Set containing global variable values";
@ -297,6 +318,7 @@ in {
result; result;
in { in {
vim = { vim = {
startPlugins = map (x: x.package) (attrValues cfg.extraPlugins);
configRC = { configRC = {
globalsScript = nvim.dag.entryAnywhere (concatStringsSep "\n" globalsScript); globalsScript = nvim.dag.entryAnywhere (concatStringsSep "\n" globalsScript);
@ -314,6 +336,27 @@ in {
in in
nvim.dag.entryAfter ["globalsScript"] luaConfig; nvim.dag.entryAfter ["globalsScript"] luaConfig;
extraPluginConfigs = let
mkSection = r: ''
-- SECTION: ${r.name}
${r.data}
'';
mapResult = r: (wrapLuaConfig (concatStringsSep "\n" (map mkSection r)));
extraPluginsDag = mapAttrs (_: {
after,
setup,
...
}:
nvim.dag.entryAfter after setup)
cfg.extraPlugins;
pluginConfig = resolveDag {
name = "extra plugins config";
dag = extraPluginsDag;
inherit mapResult;
};
in
nvim.dag.entryAfter ["luaScript"] pluginConfig;
# This is probably not the right way to set the config. I'm not sure how it should look like. # This is probably not the right way to set the config. I'm not sure how it should look like.
mappings = let mappings = let
maps = [ maps = [