2022-11-08 20:59:26 +01:00
|
|
|
{
|
2023-02-20 11:42:13 +01:00
|
|
|
lib,
|
2023-11-06 15:04:08 +01:00
|
|
|
helpers,
|
|
|
|
config,
|
|
|
|
pkgs,
|
2023-02-20 11:42:13 +01:00
|
|
|
...
|
|
|
|
}:
|
2024-05-05 19:39:35 +02:00
|
|
|
with lib;
|
|
|
|
let
|
2023-02-20 11:42:13 +01:00
|
|
|
cfg = config.plugins.luasnip;
|
2024-05-05 19:39:35 +02:00
|
|
|
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
|
|
|
|
2024-05-17 14:09:20 +02:00
|
|
|
package = helpers.mkPluginPackageOption "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>",
|
|
|
|
}
|
|
|
|
'';
|
2024-05-05 19:39:35 +02:00
|
|
|
default = { };
|
2023-10-28 15:47:36 +02:00
|
|
|
};
|
|
|
|
|
2022-11-08 20:59:26 +01:00
|
|
|
fromVscode = mkOption {
|
2024-05-05 19:39:35 +02: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'}})
|
|
|
|
#
|
|
|
|
'';
|
2024-05-05 19:39:35 +02:00
|
|
|
type = types.listOf (
|
|
|
|
types.submodule {
|
|
|
|
options = {
|
|
|
|
lazyLoad = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether or not to lazy load the snippets
|
|
|
|
'';
|
|
|
|
};
|
2022-11-08 20:59:26 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
# TODO: add option to also include the default runtimepath
|
|
|
|
paths = mkOption {
|
|
|
|
default = null;
|
|
|
|
type =
|
|
|
|
with types;
|
|
|
|
nullOr (oneOf [
|
2023-02-20 11:42:13 +01:00
|
|
|
str
|
|
|
|
path
|
2024-01-01 23:33:53 +01:00
|
|
|
helpers.nixvimTypes.rawLua
|
2024-05-05 19:39:35 +02:00
|
|
|
(listOf (oneOf [
|
|
|
|
str
|
|
|
|
path
|
|
|
|
helpers.nixvimTypes.rawLua
|
|
|
|
]))
|
2023-02-20 11:42:13 +01:00
|
|
|
]);
|
2024-05-05 19:39:35 +02:00
|
|
|
};
|
2022-11-08 20:59:26 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
exclude = mkOption {
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
List of languages to exclude, by default is empty.
|
|
|
|
'';
|
|
|
|
};
|
2022-11-08 20:59:26 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
include = mkOption {
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
List of languages to include, by default is not set.
|
|
|
|
'';
|
|
|
|
};
|
2022-11-08 20:59:26 +01:00
|
|
|
};
|
2024-05-05 19:39:35 +02:00
|
|
|
}
|
|
|
|
);
|
2022-11-08 20:59:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
# TODO: add support for snipmate
|
2023-10-28 15:47:36 +02:00
|
|
|
fromLua = mkOption {
|
2024-05-05 19:39:35 +02:00
|
|
|
default = [ ];
|
2023-10-28 15:47:36 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
]
|
|
|
|
'';
|
2024-05-05 19:39:35 +02:00
|
|
|
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 (
|
2023-10-28 15:47:36 +02:00
|
|
|
with types;
|
2024-05-05 19:39:35 +02:00
|
|
|
nullOr (oneOf [
|
|
|
|
str
|
|
|
|
path
|
|
|
|
helpers.nixvimTypes.rawLua
|
|
|
|
(listOf (oneOf [
|
|
|
|
str
|
|
|
|
path
|
|
|
|
helpers.nixvimTypes.rawLua
|
|
|
|
]))
|
|
|
|
])
|
|
|
|
) "" "Paths with snippets specified with native lua";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
2023-10-28 15:47:36 +02:00
|
|
|
};
|
2022-11-08 20:59:26 +01:00
|
|
|
};
|
|
|
|
|
2024-05-05 19:39:35 +02: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;
|
|
|
|
fromLuaLoaders = lists.map (
|
|
|
|
loader:
|
|
|
|
let
|
|
|
|
options = attrsets.getAttrs [ "paths" ] loader;
|
|
|
|
in
|
|
|
|
''
|
2023-10-28 15:47:36 +02:00
|
|
|
require("luasnip.loaders.from_lua").${optionalString loader.lazyLoad "lazy_"}load(${helpers.toLuaObject options})
|
|
|
|
''
|
2024-05-05 19:39:35 +02:00
|
|
|
) cfg.fromLua;
|
|
|
|
extraConfig = [
|
|
|
|
''
|
|
|
|
require("luasnip").config.set_config(${helpers.toLuaObject cfg.extraConfig})
|
|
|
|
''
|
|
|
|
];
|
|
|
|
in
|
2022-11-08 20:59:26 +01:00
|
|
|
mkIf cfg.enable {
|
2024-05-05 19:39:35 +02:00
|
|
|
extraPlugins = [ cfg.package ];
|
|
|
|
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
|
|
|
};
|
|
|
|
}
|