feat: improve luasnip

This commit is contained in:
Moritz Böhme 2024-10-07 09:31:06 +02:00
parent 85bab070c6
commit 22a6b5156c
No known key found for this signature in database
GPG key ID: 970C6E89EB0547A9
9 changed files with 115 additions and 67 deletions

View file

@ -5,6 +5,15 @@ let
in
{
home-manager.users.moritz.programs.nixvim = {
extraConfigLuaPre = ''
local has_words_before = function()
if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
return false
end
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_text(0, line-1, 0, line-1, col, {})[1]:match("^%s@*$") == nil
end
'';
plugins.cmp = {
autoEnableSources = true;
enable = true;
@ -27,7 +36,7 @@ in
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
elseif require("luasnip").locally_jumpable(1) then
elseif require("luasnip").locally_jumpable(1) and has_words_before() then
require("luasnip").jump(1)
else
fallback()

View file

@ -4,24 +4,35 @@ let
inherit (lib) mkEnableOption mkIf readFile;
in
{
home-manager.users.moritz.programs.nixvim = {
plugins.luasnip = {
enable = true;
settings = {
history = true;
update_events = "TextChanged,TextChangedI";
delete_check_events = "TextChanged";
ext_opts.__raw = ''
{
[require("luasnip.util.types").choiceNode] = {
active = {
virt_text = { { "<--", "Error" } },
home-manager.users.moritz = {
xdg.configFile."nvim/snippets" = {
recursive = true;
source = ../snippets;
};
programs.nixvim = {
plugins.luasnip = {
enable = true;
settings = {
history = true;
update_events = "TextChanged,TextChangedI";
delete_check_events = "TextChanged";
ext_opts.__raw = ''
{
[require("luasnip.util.types").choiceNode] = {
active = {
virt_text = { { "<--", "Error" } },
},
},
},
}
'';
ft_func.__raw = ''require("luasnip.extras.filetype_functions").from_pos_or_filetype'';
}
'';
ft_func.__raw = ''require("luasnip.extras.filetype_functions").from_pos_or_filetype'';
};
};
extraConfigLuaPost = ''
require("luasnip.loaders.from_lua").load({ paths = "~/.config/nvim/snippets" })
require("luasnip.loaders.from_snipmate").lazy_load({ paths = "~/.config/nvim/snippets" })
require("luasnip.loaders.from_vscode").lazy_load()
'';
};
};
}