return { 'neovim/nvim-lspconfig', dependencies = { 'williamboman/mason-lspconfig.nvim', "williamboman/mason.nvim", 'neovim/nvim-lspconfig', 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', 'hrsh7th/cmp-cmdline', 'micangl/cmp-vimtex', 'hrsh7th/nvim-cmp', 'windwp/nvim-autopairs', { 'L3MON4D3/LuaSnip', build = "make install_jsregexp", dependencies = { 'rafamadriz/friendly-snippets' }, }, 'j-hui/fidget.nvim', }, config = function() require('fidget').setup({}) require("nvim-autopairs").setup({}) require("mason").setup() require("mason-lspconfig").setup({ ensure_installed = { 'clangd', 'lua_ls', 'nil_ls', 'rust_analyzer', 'jedi_language_server', 'texlab', }, handlers = { function(server_name) local cmp_nvim_lsp = require("cmp_nvim_lsp") local capabilities = vim.tbl_deep_extend( "force", {}, vim.lsp.protocol.make_client_capabilities(), cmp_nvim_lsp.default_capabilities()) require("lspconfig")[server_name].setup { capabilities = capabilities } require("lspconfig").lua_ls.setup({ settings = { Lua = { diagnostics = { -- Get the language server to recognize the `vim` global globals = { 'vim' }, }, workspace = { checkThirdParty = false, library = { vim.env.VIMRUNTIME } } } } }) end, } }) 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 cmp = require('cmp') local cmp_autopairs = require('nvim-autopairs.completion.cmp') local luasnip = require('luasnip') -- require("luasnip.loaders.from_vscode").lazy_load() cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done() ) local cmp_select = { behaviour = cmp.SelectBehavior.Insert } cmp.setup({ snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) -- For `luasnip` users. end, }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.select_prev_item(cmp_select), [''] = cmp.mapping.select_next_item(cmp_select), [''] = cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Replace, }), [''] = cmp.mapping.complete(), [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }), [""] = 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_jumpable() then luasnip.expand_or_jump() elseif has_words_before() then cmp.complete() else fallback() end end, { "i", "s" }), [""] = 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" }), }), sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'vimtex' }, { name = 'luasnip' }, -- For luasnip users. }, { { name = 'buffer' }, }) }) cmp.setup.cmdline({ '/', '?' }, { mapping = cmp.mapping.preset.cmdline(), sources = { { name = 'buffer' } } }) -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline(':', { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline' } }) }) vim.diagnostic.config({ update_in_insert = true, float = { focusable = false, style = "minimal", border = "rounded", source = "always", header = "", prefix = "", } }) end }