return { -- Autocompletion 'hrsh7th/nvim-cmp', dependencies = { -- Snippet Engine & its associated nvim-cmp source 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip', -- Adds LSP completion capabilities 'hrsh7th/cmp-nvim-lsp', -- Adds a number of user-friendly snippets 'rafamadriz/friendly-snippets', }, config = function() -- See `:help cmp` vim.opt.completeopt = { 'menu', 'menuone', 'noselect' } require('luasnip.loaders.from_vscode').lazy_load() local cmp = require 'cmp' local luasnip = require 'luasnip' luasnip.config.setup {} local select_opts = { behavior = cmp.SelectBehavior.Select } cmp.setup { snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, sources = { { name = 'path' }, { name = 'nvim_lsp', keyword_length = 1 }, { name = 'buffer', keyword_length = 3 }, { name = 'luasnip', keyword_length = 2 }, }, window = { documentation = cmp.config.window.bordered() }, formatting = { fields = { 'menu', 'abbr', 'kind' }, format = function(entry, item) local menu_icon = { nvim_lsp = 'λ', luasnip = '⋗', buffer = 'Ω', path = '🖫', } item.menu = menu_icon[entry.source.name] return item end, }, mapping = cmp.mapping.preset.insert { [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete {}, [''] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true, }, [''] = 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' }), [''] = 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' }), }, } local sign = function(opts) vim.fn.sign_define(opts.name, { texthl = opts.name, text = opts.text, numhl = '' }) end sign({ name = 'DiagnosticSignError', text = '✘' }) sign({ name = 'DiagnosticSignWarn', text = '▲' }) sign({ name = 'DiagnosticSignHint', text = '⚑' }) sign({ name = 'DiagnosticSignInfo', text = '»' }) vim.diagnostic.config({ virtual_text = false, severity_sort = true, float = { border = 'rounded', source = 'always', }, }) vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( vim.lsp.handlers.hover, { border = 'rounded' } ) vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( vim.lsp.handlers.signature_help, { border = 'rounded' } ) end, }