Skip to content

Commit

Permalink
plugins/luasnip: add filetypeExtend option
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Aug 5, 2024
1 parent c0a8bfc commit 5922a48
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion plugins/snippets/luasnip/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,27 @@ in
'';
type = types.listOf loaderSubmodule;
};

filetypeExtend = mkOption {
default = { };
type = with types; attrsOf (listOf str);
example = {
lua = [
"c"
"cpp"
];
};
description = ''
Wrapper for the `filetype_extend` function.
Keys are filetypes (`filetype`) and values are list of filetypes (`["ft1" "ft2" "ft3"]`).
Tells luasnip that for a buffer with `ft=filetype`, snippets from `extend_filetypes` should
be searched as well.
For example, `filetypeExtend.lua = ["c" "cpp"]` would search and expand c and cpp snippets
for lua files.
'';
};
};

config =
Expand Down Expand Up @@ -164,6 +185,11 @@ in
''
))
];

filetypeExtendConfig = mapAttrsToList (n: v: ''
require("luasnip").extend_filetypes("${n}", ${helpers.toLuaObject v})
'') cfg.filetypeExtend;

extraConfig = [
''
require("luasnip").config.setup(${helpers.toLuaObject cfg.settings})
Expand All @@ -173,6 +199,6 @@ in
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
extraLuaPackages = ps: [ ps.jsregexp ];
extraConfigLua = concatStringsSep "\n" (extraConfig ++ loaderConfig);
extraConfigLua = concatStringsSep "\n" (extraConfig ++ loaderConfig ++ filetypeExtendConfig);
};
}

0 comments on commit 5922a48

Please sign in to comment.