-- nvim-cmp supports LSP capabilities so set it as default LSP engine local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) -- LSP setup for different programming languages local lspconfig = require('lspconfig') lspconfig.omnisharp.setup {} lspconfig.jdtls.setup { root_dir = vim.loop.cwd } lspconfig.pyright.setup {} lspconfig.bashls.setup {} lspconfig.html.setup {} lspconfig.tsserver.setup {} lspconfig.cssls.setup {} lspconfig.jsonls.setup {} lspconfig.marksman.setup {} lspconfig.yamlls.setup {} lspconfig.terraformls.setup {} lspconfig.docker_compose_language_service.setup {} lspconfig.dockerls.setup {} lspconfig.clangd.setup {} lspconfig.awk_ls.setup {} -- lua_ls LSP setup via Neodev extension which provides additional functionality require("neodev").setup() lspconfig.lua_ls.setup { settings = { Lua = { completion = { callSnippet = "Replace" } } } } -- Global mappings. -- See `:help vim.diagnostic.*` for documentation on any of the below functions vim.keymap.set('n', 'e', vim.diagnostic.open_float) vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) vim.keymap.set('n', ']d', vim.diagnostic.goto_next) vim.keymap.set('n', 'q', vim.diagnostic.setloclist) -- Use LspAttach autocommand to only map the following keys -- after the language server attaches to the current buffer vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('UserLspConfig', {}), callback = function(ev) -- Enable completion triggered by vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' -- Buffer local mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions local opts = { buffer = ev.buf } vim.keymap.set("n", "gD", "lua vim.lsp.buf.declaration()", opts) vim.keymap.set("n", "gd", "lua vim.lsp.buf.definition()", opts) vim.keymap.set("n", "K", "lua vim.lsp.buf.hover()", opts) vim.keymap.set("n", "gI", "lua vim.lsp.buf.implementation()", opts) vim.keymap.set("n", "gr", "lua vim.lsp.buf.references()", opts) vim.keymap.set("n", "gl", "lua vim.diagnostic.open_float()", opts) vim.keymap.set("n", "lf", "lua vim.lsp.buf.format{ async = true }", opts) vim.keymap.set("n", "li", "LspInfo", opts) vim.keymap.set("n", "lI", "LspInstallInfo", opts) vim.keymap.set("n", "la", "lua vim.lsp.buf.code_action()", opts) vim.keymap.set("n", "lj", "lua vim.diagnostic.goto_next({buffer=0})", opts) vim.keymap.set("n", "lk", "lua vim.diagnostic.goto_prev({buffer=0})", opts) vim.keymap.set("n", "lr", "lua vim.lsp.buf.rename()", opts) vim.keymap.set("n", "ls", "lua vim.lsp.buf.signature_help()", opts) vim.keymap.set("n", "lq", "lua vim.diagnostic.setloclist()", opts) end, })