148 lines
4.3 KiB
Lua
148 lines
4.3 KiB
Lua
-- Auto-completion / Snippets
|
|
return {
|
|
-- https://github.com/hrsh7th/nvim-cmp
|
|
"hrsh7th/nvim-cmp",
|
|
event = "InsertEnter",
|
|
dependencies = {
|
|
-- Snippet engine & associated nvim-cmp source
|
|
-- https://github.com/L3MON4D3/LuaSnip
|
|
"L3MON4D3/LuaSnip",
|
|
-- https://github.com/saadparwaiz1/cmp_luasnip
|
|
"saadparwaiz1/cmp_luasnip",
|
|
|
|
-- LSP completion capabilities
|
|
-- https://github.com/hrsh7th/cmp-nvim-lsp
|
|
"hrsh7th/cmp-nvim-lsp",
|
|
|
|
-- Additional user-friendly snippets
|
|
-- https://github.com/rafamadriz/friendly-snippets
|
|
"rafamadriz/friendly-snippets",
|
|
-- https://github.com/hrsh7th/cmp-buffer
|
|
"hrsh7th/cmp-buffer",
|
|
-- https://github.com/hrsh7th/cmp-path
|
|
"hrsh7th/cmp-path",
|
|
-- https://github.com/hrsh7th/cmp-cmdline
|
|
"hrsh7th/cmp-cmdline",
|
|
-- sql completion
|
|
"kristijanhusak/vim-dadbod-completion",
|
|
{"onsails/lspkind.nvim", lazy = true},
|
|
},
|
|
config = function()
|
|
local cmp = require("cmp")
|
|
local luasnip = require("luasnip")
|
|
local lspkind = require('lspkind')
|
|
require("luasnip.loaders.from_vscode").lazy_load()
|
|
luasnip.config.setup({})
|
|
|
|
cmp.setup({
|
|
snippet = {
|
|
expand = function(args)
|
|
luasnip.lsp_expand(args.body)
|
|
end,
|
|
},
|
|
completion = {
|
|
completeopt = "menu,menuone,noinsert",
|
|
},
|
|
mapping = cmp.mapping.preset.insert({
|
|
["<C-j>"] = cmp.mapping.select_next_item(), -- next suggestion
|
|
["<C-k>"] = cmp.mapping.select_prev_item(), -- previous suggestion
|
|
["<C-b>"] = cmp.mapping.scroll_docs(-4), -- scroll backward
|
|
["<C-f>"] = cmp.mapping.scroll_docs(4), -- scroll forward
|
|
["<C-Space>"] = cmp.mapping.complete({}), -- show completion suggestions
|
|
["<A-CR>"] = cmp.mapping.confirm({
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
select = true,
|
|
}),
|
|
-- Tab through suggestions or when a snippet is active, tab to the next argument
|
|
["<Tab>"] = cmp.mapping(function(fallback)
|
|
if cmp.visible() then
|
|
-- cmp.select_next_item()
|
|
cmp.confirm({
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
select = true,
|
|
})
|
|
elseif luasnip.expand_or_locally_jumpable() then
|
|
luasnip.expand_or_jump()
|
|
else
|
|
fallback()
|
|
end
|
|
end, { "i", "s" }),
|
|
-- Tab backwards through suggestions or when a snippet is active, tab to the next argument
|
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
|
if cmp.visible() then
|
|
cmp.select_prev_item()
|
|
elseif luasnip.locally_jumpable(-1) then
|
|
luasnip.jump(-1)
|
|
else
|
|
fallback()
|
|
end
|
|
end, { "i", "s" }),
|
|
}),
|
|
sources = cmp.config.sources({
|
|
{ name = "vim-dadbod-completion" }, -- sql
|
|
{ name = "nvim_lsp" }, -- lsp
|
|
{ name = "luasnip" }, -- snippets
|
|
{ name = "buffer" }, -- text within current buffer
|
|
{ name = "path" }, -- file system paths
|
|
}),
|
|
window = {
|
|
completion = {
|
|
width = 23,
|
|
max_height = 13,
|
|
border = "rounded",
|
|
winhighlight = "Normal:CmpPmenu,CursorLine:PmenuSel,Search:None",
|
|
-- winhighlight = "Normal:CmpPmenu,FloatBorder:CmpPmenuBorder,CursorLine:PmenuSel,Search:None",
|
|
},
|
|
documentation = {
|
|
max_width = 72,
|
|
max_height = 23,
|
|
border = "rounded",
|
|
winhighlight = "Normal:CmpDoc",
|
|
},
|
|
},
|
|
formatting = {
|
|
fields = { "kind", "abbr", "menu" },
|
|
format = function(entry, vim_item)
|
|
local kind = require("lspkind").cmp_format({
|
|
mode = "symbol_text",
|
|
maxwidth = 42,
|
|
ellipsis_char = "··",
|
|
-- show_labelDetails = true,
|
|
menu = ({
|
|
buffer = "Bfr",
|
|
nvim_lsp = "LSP",
|
|
luasnip = "Snp",
|
|
nvim_lua = "Lua",
|
|
latex_symbols = "Ltx",
|
|
})
|
|
})(entry, vim_item)
|
|
local strings = vim.split(kind.kind, "%s", { trimempty = true })
|
|
local men = kind.menu
|
|
kind.kind = (strings[1] or "") .. " "
|
|
kind.menu = (men or "") .. " | " .. (strings[2] or "")
|
|
|
|
return kind
|
|
end,
|
|
},
|
|
-- formatting = {
|
|
-- format = lspkind.cmp_format({
|
|
-- mode = "symbol_text", -- text_symbol or symbol_text
|
|
-- maxwidth = 23,
|
|
-- ellipsis_char = '..',
|
|
-- show_labelDetails = true,
|
|
-- menu = ({
|
|
-- buffer = "[Buffer]",
|
|
-- nvim_lsp = "[LSP]",
|
|
-- luasnip = "[LuaSnip]",
|
|
-- nvim_lua = "[Lua]",
|
|
-- latex_symbols = "[Latex]",
|
|
-- })
|
|
-- }),
|
|
-- },
|
|
view = {
|
|
entries = {name = 'custom', selection_order = 'near_cursor' }
|
|
},
|
|
})
|
|
end,
|
|
}
|