70 lines
2.7 KiB
Lua
70 lines
2.7 KiB
Lua
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())
|
|
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
group = vim.api.nvim_create_augroup('u-lsp-attach', { clear = true }),
|
|
callback = function(event)
|
|
local map = function(keys, func, desc, mode)
|
|
mode = mode or 'n'
|
|
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
|
|
end
|
|
|
|
local builtin = require('telescope.builtin')
|
|
map('gd', builtin.lsp_definitions, '[G]oto [D]efinition')
|
|
map('gr', builtin.lsp_references, '[G]oto [R]eferences')
|
|
map('gI', builtin.lsp_implementations, '[G]oto [I]mplementation')
|
|
map('<leader>D', builtin.lsp_type_definitions, 'Type [D]efinition')
|
|
map('<leader>ds', builtin.lsp_document_symbols, '[D]ocument [S]ymbols')
|
|
map('<leader>ws', builtin.lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
|
|
map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
|
|
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' })
|
|
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
|
|
|
|
local client = vim.lsp.get_client_by_id(event.data.client_id)
|
|
if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then
|
|
local highlight_augroup = vim.api.nvim_create_augroup('u-lsp-highlight', { clear = false })
|
|
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
|
|
buffer = event.buf,
|
|
group = highlight_augroup,
|
|
callback = vim.lsp.buf.document_highlight,
|
|
})
|
|
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
|
|
buffer = event.buf,
|
|
group = highlight_augroup,
|
|
callback = vim.lsp.buf.clear_references,
|
|
})
|
|
vim.api.nvim_create_autocmd('LspDetach', {
|
|
group = vim.api.nvim_create_augroup('u-lsp-detach', { clear = true }),
|
|
callback = function(event2)
|
|
vim.lsp.buf.clear_references()
|
|
vim.api.nvim_clear_autocmds { group = 'u-lsp-highlight', buffer = event2.buf }
|
|
end,
|
|
})
|
|
end
|
|
|
|
if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then
|
|
map('<leader>th', function()
|
|
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf })
|
|
end, '[T]oggle Inlay [H]ints')
|
|
end
|
|
end,
|
|
})
|
|
|
|
vim.lsp.enable("clangd")
|
|
vim.lsp.enable("pyright")
|
|
vim.lsp.enable("nixd")
|
|
vim.lsp.enable("lua_ls")
|
|
vim.lsp.enable("zls")
|
|
|
|
vim.lsp.config("clangd",{
|
|
cmd = {
|
|
"clangd",
|
|
"--background-index",
|
|
"--clang-tidy",
|
|
"--completion-style=bundled",
|
|
"--cross-file-rename",
|
|
"--header-insertion=iwyu",
|
|
},
|
|
capabilities=capabilities
|
|
})
|