mirror of
https://github.com/traxys/Nixfiles.git
synced 2026-02-14 11:20:19 +01:00
neovim: Isolate completion configuration
This commit is contained in:
parent
0e784cf08a
commit
3dfdb88915
2 changed files with 69 additions and 67 deletions
68
neovim/completion.nix
Normal file
68
neovim/completion.nix
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
{
|
||||
extraConfigLuaPre = ''
|
||||
local has_words_before = function()
|
||||
unpack = unpack or table.unpack
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||
end
|
||||
local luasnip = require("luasnip")
|
||||
'';
|
||||
|
||||
plugins.cmp = {
|
||||
enable = true;
|
||||
|
||||
settings = {
|
||||
snippet.expand = ''
|
||||
function(args)
|
||||
require('luasnip').lsp_expand(args.body)
|
||||
end
|
||||
'';
|
||||
mapping = {
|
||||
"<CR>" = "cmp.mapping.confirm({select = true })";
|
||||
"<C-d>" = "cmp.mapping.scroll_docs(-4)";
|
||||
"<C-f>" = "cmp.mapping.scroll_docs(4)";
|
||||
"<C-Space>" = "cmp.mapping.complete()";
|
||||
"<Tab>" = # lua
|
||||
''
|
||||
cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
|
||||
-- they way you will only jump inside the snippet region
|
||||
elseif luasnip.expand_or_locally_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
elseif has_words_before() then
|
||||
cmp.complete()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" })
|
||||
'';
|
||||
"<S-Tab>" = # lua
|
||||
''
|
||||
cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif luasnip.jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" })
|
||||
'';
|
||||
"<Down>" = "cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), {'i'})";
|
||||
"<Up>" = "cmp.mapping(cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), {'i'})";
|
||||
};
|
||||
|
||||
sources = [
|
||||
{ name = "luasnip"; }
|
||||
{ name = "nvim_lsp"; }
|
||||
{ name = "path"; }
|
||||
{ name = "buffer"; }
|
||||
{ name = "calc"; }
|
||||
{ name = "git"; }
|
||||
{ name = "omni"; }
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
imports = [
|
||||
./lsp.nix
|
||||
./notes.nix
|
||||
./completion.nix
|
||||
|
||||
./modules/commands.nix
|
||||
|
||||
|
|
@ -211,73 +212,6 @@
|
|||
|
||||
# plugins.firenvim.enable = false;
|
||||
|
||||
extraConfigLuaPre = ''
|
||||
local has_words_before = function()
|
||||
unpack = unpack or table.unpack
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||
end
|
||||
local luasnip = require("luasnip")
|
||||
'';
|
||||
|
||||
plugins.cmp = {
|
||||
enable = true;
|
||||
|
||||
settings = {
|
||||
snippet.expand = ''
|
||||
function(args)
|
||||
require('luasnip').lsp_expand(args.body)
|
||||
end
|
||||
'';
|
||||
mapping = {
|
||||
"<CR>" = "cmp.mapping.confirm({select = true })";
|
||||
"<C-d>" = "cmp.mapping.scroll_docs(-4)";
|
||||
"<C-f>" = "cmp.mapping.scroll_docs(4)";
|
||||
"<C-Space>" = "cmp.mapping.complete()";
|
||||
"<Tab>" = # lua
|
||||
''
|
||||
cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
|
||||
-- they way you will only jump inside the snippet region
|
||||
elseif luasnip.expand_or_locally_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
elseif has_words_before() then
|
||||
cmp.complete()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" })
|
||||
'';
|
||||
"<S-Tab>" = # lua
|
||||
''
|
||||
cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif luasnip.jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" })
|
||||
'';
|
||||
"<Down>" = "cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), {'i'})";
|
||||
"<Up>" = "cmp.mapping(cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), {'i'})";
|
||||
};
|
||||
|
||||
sources = [
|
||||
{ name = "luasnip"; }
|
||||
{ name = "nvim_lsp"; }
|
||||
{ name = "path"; }
|
||||
{ name = "buffer"; }
|
||||
{ name = "calc"; }
|
||||
{ name = "git"; }
|
||||
{ name = "omni"; }
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
plugins.telescope = {
|
||||
enable = true;
|
||||
extensions = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue