Skip to content

Commit 5922a48

Browse files
committed
plugins/luasnip: add filetypeExtend option
1 parent c0a8bfc commit 5922a48

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

plugins/snippets/luasnip/default.nix

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,27 @@ in
133133
'';
134134
type = types.listOf loaderSubmodule;
135135
};
136+
137+
filetypeExtend = mkOption {
138+
default = { };
139+
type = with types; attrsOf (listOf str);
140+
example = {
141+
lua = [
142+
"c"
143+
"cpp"
144+
];
145+
};
146+
description = ''
147+
Wrapper for the `filetype_extend` function.
148+
Keys are filetypes (`filetype`) and values are list of filetypes (`["ft1" "ft2" "ft3"]`).
149+
150+
Tells luasnip that for a buffer with `ft=filetype`, snippets from `extend_filetypes` should
151+
be searched as well.
152+
153+
For example, `filetypeExtend.lua = ["c" "cpp"]` would search and expand c and cpp snippets
154+
for lua files.
155+
'';
156+
};
136157
};
137158

138159
config =
@@ -164,6 +185,11 @@ in
164185
''
165186
))
166187
];
188+
189+
filetypeExtendConfig = mapAttrsToList (n: v: ''
190+
require("luasnip").extend_filetypes("${n}", ${helpers.toLuaObject v})
191+
'') cfg.filetypeExtend;
192+
167193
extraConfig = [
168194
''
169195
require("luasnip").config.setup(${helpers.toLuaObject cfg.settings})
@@ -173,6 +199,6 @@ in
173199
mkIf cfg.enable {
174200
extraPlugins = [ cfg.package ];
175201
extraLuaPackages = ps: [ ps.jsregexp ];
176-
extraConfigLua = concatStringsSep "\n" (extraConfig ++ loaderConfig);
202+
extraConfigLua = concatStringsSep "\n" (extraConfig ++ loaderConfig ++ filetypeExtendConfig);
177203
};
178204
}

0 commit comments

Comments
 (0)