Add lsp/buffer nvim-cmp completion.

main
Joshua Potter 2023-11-18 16:08:50 -07:00
parent c6e048e558
commit 74ee41cf80
3 changed files with 78 additions and 13 deletions

View File

@ -9,6 +9,13 @@ let
};
};
nvim-cmp = {
plugin = pkgs.vimPlugins.nvim-cmp;
config = ''
require('init.cmp').setup()
'';
};
nvim-dap = {
plugin = pluginGit
"e154fdb6d70b3765d71f296e718b29d8b7026a63"
@ -30,19 +37,7 @@ let
]
));
config = ''
require('nvim-treesitter.configs').setup {
auto_install = false,
highlight = { enable = true },
incremental_selection = {
enable = true,
keymaps = {
init_selection = '<Tab>',
node_incremental = '<Tab>',
node_decremental = '<S-Tab>',
scope_incremental = false,
},
},
}
require('init.treesitter').setup()
'';
};
in
@ -83,9 +78,12 @@ in
inherit (p) plugin;
config = "lua << EOF\n${p.config}\nEOF";
} else p) [
nvim-cmp
nvim-dap
nvim-lspconfig
nvim-treesitter
pkgs.vimPlugins.cmp-buffer
pkgs.vimPlugins.cmp-nvim-lsp
];
viAlias = true;
vimAlias = true;

View File

@ -0,0 +1,55 @@
local M = {}
local cmp = require('cmp')
local cmp_buffer = require('cmp_buffer')
function M.setup()
cmp.setup {
sources = {
{
name = 'nvim_lsp',
},
{
name = 'buffer',
option = {
-- Complete only on visible buffers.
get_bufnrs = function()
local bufs = {}
for _, win in ipairs(vim.api.nvim_list_wins()) do
bufs[vim.api.nvim_win_get_buf(win)] = true
end
return vim.tbl_keys(bufs)
end
},
},
},
sorting = {
comparators = {
function (...)
-- This also sorts completion results coming from other sources (e.g.
-- LSPs).
return cmp_buffer:compare_locality(...)
end,
},
},
mapping = {
['<c-n>'] = cmp.mapping(function(fallback)
if cmp.visible() then cmp.select_next_item() else fallback() end
end, { 'i', 's' }),
['<c-p>'] = cmp.mapping(function(fallback)
if cmp.visible() then cmp.select_prev_item() else fallback() end
end, { 'i', 's' }),
['<c-l>'] = cmp.mapping(function(fallback)
if cmp.visible() then cmp.abort() else fallback() end
end, { 'i', 's' }),
['<tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then cmp.confirm() else fallback() end
end, { 'i', 's' }),
},
}
end
return M

View File

@ -0,0 +1,12 @@
local M = {}
local configs = require('nvim-treesitter.configs')
function M.setup()
configs.setup {
auto_install = false,
highlight = { enable = true },
}
end
return M