local M = {} local status_cmp_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") if not status_cmp_ok then return end -- M.capabilities = vim.lsp.protocol.make_client_capabilities() M.capabilities = cmp_nvim_lsp.default_capabilities() M.capabilities.textDocument.completion.completionItem.snippetSupport = true -- M.capabilities = cmp_nvim_lsp.update_capabilities(M.capabilities) M.setup = function() local signs = { { name = "DiagnosticSignError", text = "" }, { name = "DiagnosticSignWarn", text = "" }, { name = "DiagnosticSignHint", text = "" }, { name = "DiagnosticSignInfo", text = "" }, } for _, sign in ipairs(signs) do vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) end local config = { virtual_text = true, -- disable virtual text signs = { active = signs, -- show signs }, update_in_insert = true, underline = true, severity_sort = true, float = { focusable = true, style = "minimal", border = "rounded", source = "always", header = "", prefix = "", }, } vim.diagnostic.config(config) 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 local function lsp_keymaps(bufnr) local opts = { noremap = true, silent = true } local keymap = vim.api.nvim_buf_set_keymap keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) keymap(bufnr, "n", "gI", "lua vim.lsp.buf.implementation()", opts) keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) keymap(bufnr, "n", "gl", "lua vim.diagnostic.open_float()", opts) keymap(bufnr, "n", "lf", "lua vim.lsp.buf.format{ async = true }", opts) keymap(bufnr, "v", "lf", "'<,'>lua vim.lsp.buf.format()", opts) keymap(bufnr, "x", "lf", "'<,'>lua vim.lsp.buf.format()", opts) keymap(bufnr, "n", "li", "LspInfo", opts) keymap(bufnr, "n", "lI", "LspInstallInfo", opts) keymap(bufnr, "n", "la", "lua vim.lsp.buf.code_action()", opts) keymap(bufnr, "n", "", "lua vim.lsp.buf.code_action()", opts) keymap(bufnr, "n", "lj", "lua vim.diagnostic.goto_next({buffer=0})", opts) keymap(bufnr, "n", "lk", "lua vim.diagnostic.goto_prev({buffer=0})", opts) keymap(bufnr, "n", "lr", "lua vim.lsp.buf.rename()", opts) keymap(bufnr, "n", "ls", "lua vim.lsp.buf.signature_help()", opts) keymap(bufnr, "n", "lq", "lua vim.diagnostic.setloclist()", opts) keymap(bufnr, "v", "lf", "'<,'>lua vim.lsp.buf.format{ async = true }", opts) keymap(bufnr, "x", "lf", "'<,'>lua vim.lsp.buf.format{ async = true }", opts) end M.on_attach = function(client, bufnr) if client.name == "tsserver" then client.server_capabilities.documentFormattingProvider = false end if client.name == "lua_ls" then client.server_capabilities.documentFormattingProvider = false end lsp_keymaps(bufnr) local status_ok, illuminate = pcall(require, "illuminate") if not status_ok then return end illuminate.on_attach(client) end return M