-- backward compat -- local client_has_capability = function(client, capability) -- local resolved_capabilities = { -- codeLensProvider = "code_len", -- documentFormattingProvider = "document_formatting", -- documentRangeFormattingProvider = "document_range_formatting", -- } -- if vim.fn.has("nvim-0.8") == 1 then -- return client.server_capabilities[capability] -- else -- assert(resolved_capabilities[capability]) -- capability = resolved_capabilities[capability] -- return client.resolved_capabilities[capability] -- end -- end local map = function(mode, lhs, rhs, opts) opts = vim.tbl_extend("keep", opts, { silent = true, buffer = true }) vim.keymap.set(mode, lhs, rhs, opts) end local on_attach = function(client, bufnr) vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") if client.config.flags then client.config.flags.allow_incremental_sync = true client.config.flags.debounce_text_changes = 100 end map("n", "K", "lua vim.lsp.buf.hover()", { desc = "hover information [LSP]" }) map("n", "gd", "lua vim.lsp.buf.definition()", { desc = "goto definition [LSP]" }) map("n", "gD", "lua vim.lsp.buf.declaration()", { desc = "goto declaration [LSP]" }) map("n", "gr", "lua vim.lsp.buf.references()", { desc = "goto reference [LSP]" }) map("n", "gm", "lua vim.lsp.buf.implementation()", { desc = "goto implementation [LSP]" }) map("n", "gy", "lua vim.lsp.buf.type_definition()", { desc = "goto type definition [LSP]" }) map("n", "gA", "lua vim.lsp.buf.code_action()", { desc = "code actions [LSP]" }) map("v", "gA", "lua vim.lsp.buf.range_code_action()", { desc = "range code actions [LSP]" }) -- use our own rename popup implementation map("n", "gR", [[lua require("lsp.rename").rename()]], { desc = "rename [LSP]" }) map("n", "lR", [[lua require("lsp.rename").rename()]], { desc = "rename [LSP]" }) map("n", "K", "lua vim.lsp.buf.signature_help()", { desc = "signature help [LSP]" }) map("n", "k", [[lua require("lsp.handlers").peek_definition()]], { desc = "peek definition [LSP]" }) -- using fzf-lua instead --map('n', 'ls', 'lua vim.lsp.buf.document_symbol()') --map('n', 'lS', 'lua vim.lsp.buf.workspace_symbol()') map("n", "lt", "lua require'lsp.diag'.toggle()", { desc = "toggle virtual text [LSP]" }) -- neovim PR #16057 -- https://github.com/neovim/neovim/pull/16057 local winopts = "{ float = { border = 'rounded' } }" map("n", "[d", ("lua vim.diagnostic.goto_prev(%s)"):format(winopts), { desc = "previous diagnostic [LSP]" }) map("n", "]d", ("lua vim.diagnostic.goto_next(%s)"):format(winopts), { desc = "next diagnostic [LSP]" }) map("n", "lc", "lua vim.diagnostic.reset()", { desc = "clear diagnostics [LSP]" }) map("n", "l?", [[lua vim.diagnostic.open_float(0, { scope = "line", border = "rounded" })]], { desc = "show line diagnostic [LSP]" }) map("n", "lq", "lua vim.diagnostic.setqflist()", { desc = "send diagnostics to quickfix [LSP]" }) map("n", "lQ", "lua vim.diagnostic.setloclist()", { desc = "send diagnostics to loclist [LSP]" }) -- if client_has_capability(client, "codeLensProvider") then -- map("n", "lL", "lua vim.lsp.codelens.run()", -- { desc = "[LSP] code lens" }) -- vim.api.nvim_command -- [[autocmd CursorHold,CursorHoldI,InsertLeave lua vim.lsp.codelens.refresh()]] -- end end return { on_attach = on_attach }