2022-11-08 20:59:26 +01:00
|
|
|
{
|
2023-02-20 11:42:13 +01:00
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
cfg = config.plugins.luasnip;
|
|
|
|
helpers = import ../../helpers.nix {inherit lib;};
|
|
|
|
in {
|
2022-11-08 20:59:26 +01:00
|
|
|
options.plugins.luasnip = {
|
2023-10-09 07:58:51 -05:00
|
|
|
enable = mkEnableOption "luasnip";
|
2022-11-08 20:59:26 +01:00
|
|
|
|
2023-01-25 19:46:49 +01:00
|
|
|
package = helpers.mkPackageOption "luasnip" pkgs.vimPlugins.luasnip;
|
2022-11-08 20:59:26 +01:00
|
|
|
|
2023-10-28 15:47:36 +02:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.attrsOf types.anything;
|
|
|
|
description = ''
|
|
|
|
Extra config options for luasnip.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
{
|
|
|
|
enable_autosnippets = true,
|
|
|
|
store_selection_keys = "<Tab>",
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
|
2022-11-08 20:59:26 +01:00
|
|
|
fromVscode = mkOption {
|
2023-02-20 11:42:13 +01:00
|
|
|
default = [];
|
2022-11-08 20:59:26 +01:00
|
|
|
example = ''
|
|
|
|
[
|
|
|
|
{}
|
|
|
|
{
|
|
|
|
paths = ./path/to/snippets;
|
|
|
|
}
|
|
|
|
]
|
|
|
|
# generates:
|
2023-01-21 18:12:09 +01:00
|
|
|
#
|
2022-11-08 20:59:26 +01:00
|
|
|
# require("luasnip.loaders.from_vscode").lazy_load({})
|
|
|
|
# require("luasnip.loaders.from_vscode").lazy_load({['paths'] = {'/nix/store/.../path/to/snippets'}})
|
|
|
|
#
|
|
|
|
'';
|
|
|
|
type = types.listOf (types.submodule {
|
|
|
|
options = {
|
|
|
|
lazyLoad = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether or not to lazy load the snippets
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# TODO: add option to also include the default runtimepath
|
|
|
|
paths = mkOption {
|
|
|
|
default = null;
|
2023-02-20 11:42:13 +01:00
|
|
|
type = with types;
|
|
|
|
nullOr (oneOf
|
|
|
|
[
|
|
|
|
str
|
|
|
|
path
|
|
|
|
helpers.rawType
|
|
|
|
(listOf (oneOf
|
|
|
|
[
|
|
|
|
str
|
|
|
|
path
|
|
|
|
helpers.rawType
|
|
|
|
]))
|
|
|
|
]);
|
2022-11-08 20:59:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exclude = mkOption {
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
List of languages to exclude, by default is empty.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
include = mkOption {
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
List of languages to include, by default is not set.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
# TODO: add support for snipmate
|
2023-10-28 15:47:36 +02:00
|
|
|
fromLua = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Load lua snippets with the lua loader.
|
|
|
|
Check https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#lua for the necessary file structure.
|
|
|
|
'';
|
|
|
|
example = ''
|
|
|
|
[
|
|
|
|
{}
|
|
|
|
{
|
|
|
|
paths = ./path/to/snippets;
|
|
|
|
}
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
type = types.listOf (types.submodule {
|
|
|
|
options = {
|
|
|
|
lazyLoad = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether or not to lazy load the snippets
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
paths =
|
|
|
|
helpers.defaultNullOpts.mkNullable
|
|
|
|
(
|
|
|
|
with types;
|
|
|
|
nullOr (
|
|
|
|
oneOf
|
|
|
|
[
|
|
|
|
str
|
|
|
|
path
|
|
|
|
helpers.rawType
|
|
|
|
(listOf (oneOf
|
|
|
|
[
|
|
|
|
str
|
|
|
|
path
|
|
|
|
helpers.rawType
|
|
|
|
]))
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
""
|
|
|
|
"Paths with snippets specified with native lua";
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
2022-11-08 20:59:26 +01:00
|
|
|
};
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
config = let
|
|
|
|
fromVscodeLoaders =
|
|
|
|
lists.map
|
|
|
|
(loader: let
|
|
|
|
options = attrsets.getAttrs ["paths" "exclude" "include"] loader;
|
|
|
|
in ''
|
|
|
|
require("luasnip.loaders.from_vscode").${optionalString loader.lazyLoad "lazy_"}load(${helpers.toLuaObject options})
|
|
|
|
'')
|
|
|
|
cfg.fromVscode;
|
2023-10-28 15:47:36 +02:00
|
|
|
fromLuaLoaders =
|
|
|
|
lists.map
|
|
|
|
(
|
|
|
|
loader: let
|
|
|
|
options = attrsets.getAttrs ["paths"] loader;
|
|
|
|
in ''
|
|
|
|
require("luasnip.loaders.from_lua").${optionalString loader.lazyLoad "lazy_"}load(${helpers.toLuaObject options})
|
|
|
|
''
|
|
|
|
)
|
|
|
|
cfg.fromLua;
|
|
|
|
extraConfig = [
|
|
|
|
''
|
|
|
|
require("luasnip").config.set_config(${helpers.toLuaObject cfg.extraConfig})
|
|
|
|
''
|
|
|
|
];
|
2023-02-20 11:42:13 +01:00
|
|
|
in
|
2022-11-08 20:59:26 +01:00
|
|
|
mkIf cfg.enable {
|
2023-02-20 11:42:13 +01:00
|
|
|
extraPlugins = [cfg.package];
|
2023-03-18 22:44:34 +01:00
|
|
|
extraLuaPackages = ps: [ps.jsregexp];
|
2023-10-28 15:47:36 +02:00
|
|
|
extraConfigLua = concatStringsSep "\n" (extraConfig ++ fromVscodeLoaders ++ fromLuaLoaders);
|
2022-11-08 20:59:26 +01:00
|
|
|
};
|
|
|
|
}
|