local ok, lsp = pcall(require, 'lspconfig') if not ok then return end local sign = function(opts) -- See :help sign_define() vim.fn.sign_define(opts.name, { texthl = opts.name, text = opts.text, numhl = '' }) end sign({name = 'DiagnosticSignError', text = '✘'}) sign({name = 'DiagnosticSignWarn', text = '▲'}) sign({name = 'DiagnosticSignHint', text = '⚑'}) sign({name = 'DiagnosticSignInfo', text = ''}) vim.diagnostic.config({ virtual_text = false, severity_sort = true, float = { border = 'rounded', source = 'always', header = '', prefix = '', }, }) 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'} ) vim.lsp.handlers["workspace/diagnostic/refresh"] = function(_, _, ctx) local ns = vim.lsp.diagnostic.get_namespace(ctx.client_id) pcall(vim.diagnostic.reset, ns) return true end require("lsp-format").setup {} local on_attach = function(client) local bufmap = function(mode, lhs, rhs) local opts = {buffer = true} vim.keymap.set(mode, lhs, rhs, opts) end require("lsp-format").on_attach(client) bufmap('n', 'K', 'lua vim.lsp.buf.hover()') bufmap('n', 'gd', 'lua vim.lsp.buf.definition()') bufmap('n', 'gD', 'lua vim.lsp.buf.declaration()') bufmap('n', 'go', 'lua vim.lsp.buf.type_definition()') bufmap('n', 'gs', 'lua vim.lsp.buf.signature_help()') bufmap('n', 'gA', 'Telescope diagnostics') bufmap('n', 'gr', 'Telescope lsp_references') bufmap('n', 'gi', 'Telescope lsp_implementations') bufmap('n', '', 'lua vim.lsp.buf.rename()') bufmap('n', '', 'lua vim.lsp.buf.format({async = true})') bufmap('n', '', 'lua vim.lsp.buf.code_action()') bufmap('x', '', 'lua vim.lsp.buf.range_code_action()') bufmap('n', 'gl', 'lua vim.diagnostic.open_float()') bufmap('n', '[d', 'lua vim.diagnostic.goto_prev()') bufmap('n', ']d', 'lua vim.diagnostic.goto_next()') end lsp.gopls.setup { on_attach = on_attach } lsp.clangd.setup { on_attach = on_attach } lsp.ltex.setup { on_attach = on_attach } lsp.svelte.setup { on_attach = on_attach } lsp.tsserver.setup { on_attach = on_attach } lsp.lua_ls.setup { settings = { Lua = { diagnostics = { globals = { 'vim' } }, -- workspace = { -- library = vim.api.nvim_get_runtime_file("", true), -- }, -- telemetry = { -- enable = false, -- }, } }, on_attach = on_attach }