1return { 2 'neovim/nvim-lspconfig', 3 dependencies = { 4 'williamboman/mason-lspconfig.nvim', 5 "williamboman/mason.nvim", 6 'neovim/nvim-lspconfig', 7 'hrsh7th/cmp-nvim-lsp', 8 'hrsh7th/cmp-buffer', 9 'hrsh7th/cmp-path', 10 'hrsh7th/cmp-cmdline', 11 'micangl/cmp-vimtex', 12 'hrsh7th/nvim-cmp', 13 'windwp/nvim-autopairs', 14 { 15 'L3MON4D3/LuaSnip', 16 build = "make install_jsregexp", 17 dependencies = { 18 'rafamadriz/friendly-snippets' 19 }, 20 }, 21 'j-hui/fidget.nvim', 22 }, 23 config = function() 24 require('fidget').setup({}) 25 require("nvim-autopairs").setup({}) 26 require("mason").setup({ 27 PATH="append", 28 }) 29 require("mason-lspconfig").setup({ 30 ensure_installed = { 31 'clangd', 32 'lua_ls', 33 'nil_ls', 34 'rust_analyzer', 35 'jedi_language_server', 36 'texlab', 37 }, 38 handlers = { 39 function(server_name) 40 local cmp_nvim_lsp = require("cmp_nvim_lsp") 41 local capabilities = vim.tbl_deep_extend( 42 "force", 43 {}, 44 vim.lsp.protocol.make_client_capabilities(), 45 cmp_nvim_lsp.default_capabilities()) 46 47 require("lspconfig")[server_name].setup { 48 capabilities = capabilities 49 } 50 require("lspconfig").lua_ls.setup({ 51 settings = { 52 Lua = { 53 diagnostics = { 54 -- Get the language server to recognize the `vim` global 55 globals = { 'vim' }, 56 }, 57 workspace = { 58 checkThirdParty = false, 59 library = { 60 vim.env.VIMRUNTIME 61 } 62 } 63 } 64 } 65 }) 66 end, 67 } 68 }) 69 70 71 local has_words_before = function() 72 unpack = unpack or table.unpack 73 local line, col = unpack(vim.api.nvim_win_get_cursor(0)) 74 return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil 75 end 76 77 78 local cmp = require('cmp') 79 local cmp_autopairs = require('nvim-autopairs.completion.cmp') 80 81 82 local luasnip = require('luasnip') 83 -- require("luasnip.loaders.from_vscode").lazy_load() 84 85 cmp.event:on( 86 'confirm_done', 87 cmp_autopairs.on_confirm_done() 88 ) 89 local cmp_select = { behaviour = cmp.SelectBehavior.Insert } 90 cmp.setup({ 91 snippet = { 92 expand = function(args) 93 require('luasnip').lsp_expand(args.body) -- For `luasnip` users. 94 end, 95 }, 96 mapping = cmp.mapping.preset.insert({ 97 ['<C-p>'] = cmp.mapping.select_prev_item(cmp_select), 98 ['<C-n>'] = cmp.mapping.select_next_item(cmp_select), 99 ['<CR>'] = cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Replace, }), 100 ['<C-Space>'] = cmp.mapping.complete(), 101 ['<C-u>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), 102 ['<C-d>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }), 103 ["<Tab>"] = cmp.mapping(function(fallback) 104 if cmp.visible() then 105 cmp.select_next_item() 106 -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() 107 -- they way you will only jump inside the snippet region 108 elseif luasnip.expand_or_jumpable() then 109 luasnip.expand_or_jump() 110 elseif has_words_before() then 111 cmp.complete() 112 else 113 fallback() 114 end 115 end, { "i", "s" }), 116 117 ["<S-Tab>"] = cmp.mapping(function(fallback) 118 if cmp.visible() then 119 cmp.select_prev_item() 120 elseif luasnip.jumpable(-1) then 121 luasnip.jump(-1) 122 else 123 fallback() 124 end 125 end, { "i", "s" }), 126 }), 127 sources = cmp.config.sources({ 128 { name = 'nvim_lsp' }, 129 { name = 'vimtex' }, 130 { name = 'luasnip' }, -- For luasnip users. 131 }, { 132 { name = 'buffer' }, 133 }) 134 }) 135 cmp.setup.cmdline({ '/', '?' }, { 136 mapping = cmp.mapping.preset.cmdline(), 137 sources = { 138 { name = 'buffer' } 139 } 140 }) 141 142 -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). 143 cmp.setup.cmdline(':', { 144 mapping = cmp.mapping.preset.cmdline(), 145 sources = cmp.config.sources({ 146 { name = 'path' } 147 }, { 148 { name = 'cmdline' } 149 }) 150 }) 151 152 vim.diagnostic.config({ 153 update_in_insert = true, 154 float = { 155 focusable = false, 156 style = "minimal", 157 border = "rounded", 158 source = "always", 159 header = "", 160 prefix = "", 161 } 162 }) 163 end 164}