2024-08-06 16:35:29 +02:00
|
|
|
-- Install and configure nvim-cmp to provide completion
|
|
|
|
|
|
|
|
-- Install nvim-cmp and dependencies
|
|
|
|
return {
|
|
|
|
"hrsh7th/nvim-cmp",
|
|
|
|
event = { "InsertEnter", "CmdlineEnter" },
|
|
|
|
dependencies = {
|
|
|
|
-- Adds completion capabilities for text in buffers
|
|
|
|
"hrsh7th/cmp-buffer",
|
|
|
|
-- Adds path completion capabilities
|
|
|
|
"hrsh7th/cmp-path",
|
|
|
|
-- Adds vim cmdline completion capabilities
|
|
|
|
"hrsh7th/cmp-cmdline",
|
|
|
|
|
|
|
|
-- Snippet Engine & its associated nvim-cmp source
|
|
|
|
{
|
|
|
|
"L3MON4D3/LuaSnip",
|
|
|
|
-- Follow latest release
|
|
|
|
version = "v2.*",
|
|
|
|
-- Install jsregexp (optional)
|
|
|
|
build = "make install_jsregexp",
|
|
|
|
},
|
|
|
|
"saadparwaiz1/cmp_luasnip",
|
|
|
|
-- Adds a number of user-friendly snippets
|
|
|
|
"rafamadriz/friendly-snippets",
|
|
|
|
|
|
|
|
-- Adds emoji completion after ':' (to be evaluated)
|
|
|
|
"hrsh7th/cmp-emoji",
|
|
|
|
-- vs-code pictrograms
|
|
|
|
"onsails/lspkind.nvim",
|
2024-10-04 13:56:39 +02:00
|
|
|
|
|
|
|
-- Completion source for code emmbedded in other documents
|
|
|
|
"jmbuh/otter.nvim",
|
2024-08-06 16:35:29 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
-- Configure nvim-cmp
|
|
|
|
config = function()
|
|
|
|
local cmp = require("cmp")
|
|
|
|
|
|
|
|
local luasnip = require("luasnip")
|
|
|
|
|
|
|
|
local lspkind = require("lspkind")
|
|
|
|
|
|
|
|
luasnip.config.setup {
|
|
|
|
-- Extend markdown snippets to pandoc filetype
|
2024-10-04 13:56:39 +02:00
|
|
|
-- https://github.com/L3MON4D3/LuaSnip/issues/132#issuecomment-1101731222
|
2024-08-06 16:35:29 +02:00
|
|
|
snippets = {
|
|
|
|
markdown = {},
|
|
|
|
},
|
|
|
|
luasnip.filetype_extend("pandoc", {"markdown"}),
|
2024-10-04 13:56:39 +02:00
|
|
|
luasnip.filetype_extend("quarto", {"markdown"}),
|
2024-08-06 16:35:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
-- Load snippets from ~/.config/nvim/my_snippets/
|
|
|
|
require("luasnip.loaders.from_lua").lazy_load(
|
2024-10-04 13:56:39 +02:00
|
|
|
{ paths = "~/.config/nvim/my_snippets/" }
|
2024-08-06 16:35:29 +02:00
|
|
|
)
|
|
|
|
require("luasnip.loaders.from_vscode").lazy_load()
|
|
|
|
|
|
|
|
cmp.setup({
|
|
|
|
completion = {
|
|
|
|
completeopt = "menu,menuone,preview,noselect",
|
|
|
|
},
|
|
|
|
snippet = { -- on utilise luasnip comme moteur de snippets
|
|
|
|
expand = function(args)
|
|
|
|
luasnip.lsp_expand(args.body)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
mapping = {
|
|
|
|
["<C-p>"] = cmp.mapping.select_prev_item(),
|
|
|
|
["<C-n>"] = cmp.mapping.select_next_item(),
|
|
|
|
["<C-d>"] = cmp.mapping.scroll_docs(-1),
|
|
|
|
["<C-f>"] = cmp.mapping.scroll_docs(1),
|
|
|
|
["<C-Space>"] = cmp.mapping.complete(),
|
|
|
|
["<C-e>"] = cmp.mapping.abort(),
|
|
|
|
-- Insert current selection.
|
|
|
|
-- `false` insert only explicitly selected items
|
|
|
|
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
|
|
|
['<Tab>'] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
elseif luasnip.expand_or_locally_jumpable() then
|
|
|
|
luasnip.expand_or_jump()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { 'i', 's' }),
|
|
|
|
['<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' }),
|
|
|
|
},
|
|
|
|
|
|
|
|
-- Autocompletion sources
|
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = "nvim_lsp" },
|
|
|
|
{ name = "nvim_lua" },
|
|
|
|
{ name = "lazydev" },
|
|
|
|
{ name = "luasnip" }, -- snippets
|
|
|
|
{
|
|
|
|
name = "buffer",
|
|
|
|
option = {
|
|
|
|
keyword_length = 4,
|
|
|
|
keyword_pattern = [[\k\+]],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ name = "path" },
|
|
|
|
{ name = "emoji" },
|
|
|
|
}),
|
|
|
|
|
|
|
|
formatting = {
|
|
|
|
-- Default behavior
|
|
|
|
expandable_indicator = true,
|
|
|
|
-- Default display fields
|
|
|
|
fields = { "abbr", "kind", "menu" },
|
|
|
|
format = lspkind.cmp_format({
|
|
|
|
mode = "symbol_text",
|
|
|
|
-- Each entry is prefixed by it's type
|
|
|
|
menu = {
|
|
|
|
nvim_lsp = "[LSP]",
|
|
|
|
buffer = "[Buffer]",
|
|
|
|
luasnip = "[LuaSnip]",
|
|
|
|
nvim_lua = "[Lua]",
|
|
|
|
lazydev = "[Lazydev]",
|
|
|
|
path = "[Path]",
|
|
|
|
emoji = "[Emoji]",
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|