-- Setup nvim-cmp. local cmp = require 'cmp' cmp.setup({ snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) end, }, mapping = { [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }), [''] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c' }), [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. [''] = cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close(), }), -- Accept currently selected item. If none selected, `select` first item. -- Set `select` to `false` to only confirm explicitly selected items. [''] = cmp.mapping.confirm({ select = true }), }, sources = cmp.config.sources({ { name = 'nvim_lsp', entry_filter = function(entry, ctx) return require('cmp.types').lsp.CompletionItemKind[entry:get_kind()] ~= 'Text' end, }, { name = 'luasnip' }, { name = 'buffer', keyword_length = 5 }, }), experimental = { native_menu = false, ghost_text = true, } }) -- Use cmdline & path source for ':' cmp.setup.cmdline(':', { sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline' } }) }) local on_attach = function(client, bufnr) local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end local opts = { noremap = true, silent = true, buffer=0 } vim.keymap.set("n", "gd", "Telescope lsp_definitions", opts) vim.keymap.set("n", "gD", "Telescope lsp_implementations", opts) vim.keymap.set("n", "gf", function() vim.lsp.buf.format {async = true} end, opts) vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) vim.keymap.set("n", "ge", vim.diagnostic.open_float, opts) vim.keymap.set("n", "gs", vim.lsp.buf.signature_help, opts) vim.keymap.set("n", "gR", vim.lsp.buf.rename, opts) vim.keymap.set("n", "gH", vim.lsp.buf.code_action, opts) end -- LSP INSTALLER require("mason").setup() require("mason-lspconfig").setup() require("mason-lspconfig").setup_handlers { -- The first entry (without a key) will be the default handler -- and will be called for each installed server that doesn't have -- a dedicated handler. function (server_name) -- default handler (optional) require("lspconfig")[server_name].setup { on_attach = on_attach, capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) } end, -- Next, you can provide a dedicated handler for specific servers. -- For example, a handler override for the `rust_analyzer`: ["rust_analyzer"] = function () require("rust-tools").setup {} end } -- EXTRA SETUP require'lspconfig'.lua_ls.setup { settings = { Lua = { runtime = { -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) version = 'LuaJIT', }, diagnostics = { -- Get the language server to recognize the `vim` global globals = {'vim'}, }, workspace = { -- Make the server aware of Neovim runtime files library = vim.api.nvim_get_runtime_file("", true), }, -- Do not send telemetry data containing a randomized but unique identifier telemetry = { enable = false, }, }, }, } -- LSP SIGNATURE require "lsp_signature".setup { handler_opts = { border = "rounded" }, toggle_key = "", }