mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
plugins/luasnip: add SnipMate loader
This commit is contained in:
parent
0ddf66249f
commit
0f2c31e6a5
1 changed files with 85 additions and 96 deletions
|
@ -8,6 +8,46 @@
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
cfg = config.plugins.luasnip;
|
cfg = config.plugins.luasnip;
|
||||||
|
|
||||||
|
loaderSubmodule = 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 =
|
||||||
|
helpers.mkNullOrOption
|
||||||
|
(
|
||||||
|
with helpers.nixvimTypes;
|
||||||
|
oneOf [
|
||||||
|
str
|
||||||
|
path
|
||||||
|
rawLua
|
||||||
|
(listOf (oneOf [
|
||||||
|
str
|
||||||
|
path
|
||||||
|
rawLua
|
||||||
|
]))
|
||||||
|
]
|
||||||
|
)
|
||||||
|
''
|
||||||
|
List of paths to load.
|
||||||
|
'';
|
||||||
|
|
||||||
|
exclude = helpers.mkNullOrOption (with helpers.nixvimTypes; maybeRaw (listOf (maybeRaw str))) ''
|
||||||
|
List of languages to exclude, by default is empty.
|
||||||
|
'';
|
||||||
|
|
||||||
|
include = helpers.mkNullOrOption (with helpers.nixvimTypes; maybeRaw (listOf (maybeRaw str))) ''
|
||||||
|
List of languages to include, by default is not set.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.plugins.luasnip = {
|
options.plugins.luasnip = {
|
||||||
|
@ -44,55 +84,24 @@ in
|
||||||
# require("luasnip.loaders.from_vscode").lazy_load({['paths'] = {'/nix/store/.../path/to/snippets'}})
|
# require("luasnip.loaders.from_vscode").lazy_load({['paths'] = {'/nix/store/.../path/to/snippets'}})
|
||||||
#
|
#
|
||||||
'';
|
'';
|
||||||
type = types.listOf (
|
type = types.listOf loaderSubmodule;
|
||||||
types.submodule {
|
};
|
||||||
options = {
|
|
||||||
lazyLoad = mkOption {
|
fromSnipmate = mkOption {
|
||||||
type = types.bool;
|
default = [ ];
|
||||||
default = true;
|
description = ''
|
||||||
description = ''
|
Luasnip does not support the full snipmate format: Only
|
||||||
Whether or not to lazy load the snippets
|
`./{ft}.snippets` and `./{ft}/*.snippets` will be loaded. See
|
||||||
'';
|
<https://github.com/honza/vim-snippets> for lots of examples.
|
||||||
};
|
'';
|
||||||
|
example = literalExpression ''
|
||||||
# TODO: add option to also include the default runtimepath
|
[
|
||||||
paths = mkOption {
|
{ }
|
||||||
default = null;
|
{ paths = ./path/to/snippets; }
|
||||||
type =
|
]'';
|
||||||
with types;
|
type = types.listOf loaderSubmodule;
|
||||||
nullOr (oneOf [
|
|
||||||
str
|
|
||||||
path
|
|
||||||
helpers.nixvimTypes.rawLua
|
|
||||||
(listOf (oneOf [
|
|
||||||
str
|
|
||||||
path
|
|
||||||
helpers.nixvimTypes.rawLua
|
|
||||||
]))
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
|
||||||
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
|
|
||||||
fromLua = mkOption {
|
fromLua = mkOption {
|
||||||
default = [ ];
|
default = [ ];
|
||||||
description = ''
|
description = ''
|
||||||
|
@ -107,59 +116,39 @@ in
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
'';
|
'';
|
||||||
type = types.listOf (
|
type = types.listOf loaderSubmodule;
|
||||||
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.nixvimTypes.rawLua
|
|
||||||
(listOf (oneOf [
|
|
||||||
str
|
|
||||||
path
|
|
||||||
helpers.nixvimTypes.rawLua
|
|
||||||
]))
|
|
||||||
])
|
|
||||||
) "" "Paths with snippets specified with native lua";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config =
|
config =
|
||||||
let
|
let
|
||||||
fromVscodeLoaders = lists.map (
|
loaderConfig =
|
||||||
loader:
|
trivial.pipe
|
||||||
let
|
{
|
||||||
options = attrsets.getAttrs [
|
vscode = cfg.fromVscode;
|
||||||
"paths"
|
snipmate = cfg.fromSnipmate;
|
||||||
"exclude"
|
lua = cfg.fromLua;
|
||||||
"include"
|
}
|
||||||
] loader;
|
[
|
||||||
in
|
# Convert loader options to [{ name = "vscode"; loader = ...; }]
|
||||||
''
|
(attrsets.mapAttrsToList (name: loaders: lists.map (loader: { inherit name loader; }) loaders))
|
||||||
require("luasnip.loaders.from_vscode").${optionalString loader.lazyLoad "lazy_"}load(${helpers.toLuaObject options})
|
lists.flatten
|
||||||
''
|
|
||||||
) cfg.fromVscode;
|
(lists.map (
|
||||||
fromLuaLoaders = lists.map (
|
pair:
|
||||||
loader:
|
let
|
||||||
let
|
inherit (pair) name loader;
|
||||||
options = attrsets.getAttrs [ "paths" ] loader;
|
options = attrsets.getAttrs [
|
||||||
in
|
"paths"
|
||||||
''
|
"exclude"
|
||||||
require("luasnip.loaders.from_lua").${optionalString loader.lazyLoad "lazy_"}load(${helpers.toLuaObject options})
|
"include"
|
||||||
''
|
] loader;
|
||||||
) cfg.fromLua;
|
in
|
||||||
|
''
|
||||||
|
require("luasnip.loaders.from_${name}").${optionalString loader.lazyLoad "lazy_"}load(${helpers.toLuaObject options})
|
||||||
|
''
|
||||||
|
))
|
||||||
|
];
|
||||||
extraConfig = [
|
extraConfig = [
|
||||||
''
|
''
|
||||||
require("luasnip").config.set_config(${helpers.toLuaObject cfg.extraConfig})
|
require("luasnip").config.set_config(${helpers.toLuaObject cfg.extraConfig})
|
||||||
|
@ -169,6 +158,6 @@ in
|
||||||
mkIf cfg.enable {
|
mkIf cfg.enable {
|
||||||
extraPlugins = [ cfg.package ];
|
extraPlugins = [ cfg.package ];
|
||||||
extraLuaPackages = ps: [ ps.jsregexp ];
|
extraLuaPackages = ps: [ ps.jsregexp ];
|
||||||
extraConfigLua = concatStringsSep "\n" (extraConfig ++ fromVscodeLoaders ++ fromLuaLoaders);
|
extraConfigLua = concatStringsSep "\n" (extraConfig ++ loaderConfig);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue