cleanup lsp
This commit is contained in:
parent
39d973b28b
commit
92ec6976c5
@ -1,31 +1,35 @@
|
|||||||
local lspKeys = function(client, bufnr)
|
local lspKeys = function(client, bufnr)
|
||||||
local options = { noremap = true, silent = false, buffer = bufnr }
|
local base_opts = { noremap = true, silent = false, buffer = bufnr }
|
||||||
vim.keymap.set({ 'n', 'x' }, '<space>a', vim.lsp.buf.code_action, vim.tbl_extend('error', options, { desc = 'Code action' }))
|
|
||||||
vim.keymap.set('n', '<space>e', vim.lsp.buf.declaration, vim.tbl_extend('error', options, { desc = 'Declaration' }))
|
local function opts(desc) return vim.tbl_extend('error', base_opts, { desc = desc }) end
|
||||||
vim.keymap.set('n', '<space>h', function()
|
|
||||||
vim.lsp.buf.hover({ border = 'none' })
|
local mappings = {
|
||||||
end, vim.tbl_extend('error', options, { desc = 'Hover' }))
|
{ mode = { 'n', 'x' }, key = '<space>a', fn = vim.lsp.buf.code_action, desc = 'Code action' },
|
||||||
vim.keymap.set('n', '<space>c', vim.lsp.buf.outgoing_calls, vim.tbl_extend('error', options, { desc = 'Outgoing calls' }))
|
{ mode = 'n', key = '<space>e', fn = vim.lsp.buf.declaration, desc = 'Declaration' },
|
||||||
vim.keymap.set('n', '<space>C', vim.lsp.buf.incoming_calls, vim.tbl_extend('error', options, { desc = 'Incoming calls' }))
|
{ mode = 'n', key = '<space>h', fn = function() vim.lsp.buf.hover({ border = 'none' }) end, desc = 'Hover' },
|
||||||
vim.keymap.set('n', '<space>m', vim.lsp.buf.rename, vim.tbl_extend('error', options, { desc = 'Rename' }))
|
{ mode = 'n', key = '<space>c', fn = vim.lsp.buf.outgoing_calls, desc = 'Outgoing calls' },
|
||||||
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, vim.tbl_extend('error', options, { desc = 'Type definition' }))
|
{ mode = 'n', key = '<space>C', fn = vim.lsp.buf.incoming_calls, desc = 'Incoming calls' },
|
||||||
vim.keymap.set({ 'n', 'i', 'x' }, '<C-k>', vim.lsp.buf.signature_help, vim.tbl_extend('error', options, { desc = 'Signature help' }))
|
{ mode = 'n', key = '<space>m', fn = vim.lsp.buf.rename, desc = 'Rename' },
|
||||||
vim.keymap.set('n', '<space>v', function()
|
{ mode = 'n', key = '<space>D', fn = vim.lsp.buf.type_definition, desc = 'Type definition' },
|
||||||
vim.diagnostic.open_float({ border = 'rounded' })
|
{ mode = { 'n', 'i', 'x' }, key = '<C-k>', fn = vim.lsp.buf.signature_help, desc = 'Signature help' },
|
||||||
end, vim.tbl_extend('error', options, { desc = 'Diagnostics Float' }))
|
{ mode = 'n', key = '<space>v', fn = function() vim.diagnostic.open_float({ border = 'rounded' }) end, desc = 'Diagnostics Float' },
|
||||||
vim.keymap.set('n', '<A-o>', '<cmd>ClangdSwitchSourceHeader<CR>', vim.tbl_extend('error', options, { desc = 'Switch Source/Header' }))
|
{ mode = 'n', key = '<A-o>', fn = '<cmd>ClangdSwitchSourceHeader<CR>', desc = 'Switch Source/Header' },
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, map in ipairs(mappings) do
|
||||||
|
vim.keymap.set(map.mode, map.key, map.fn, opts(map.desc))
|
||||||
|
end
|
||||||
|
|
||||||
if client.supports_method('inlayHintProvider') then
|
if client.supports_method('inlayHintProvider') then
|
||||||
vim.keymap.set('n', '<space>i', function()
|
vim.keymap.set(
|
||||||
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr })
|
'n',
|
||||||
end, {
|
'<space>i',
|
||||||
noremap = true,
|
function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr }) end,
|
||||||
silent = false,
|
opts('Toggle inlay hints')
|
||||||
desc = 'Toggle inlay hints',
|
)
|
||||||
buffer = bufnr,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
'neovim/nvim-lspconfig',
|
'neovim/nvim-lspconfig',
|
||||||
@ -83,12 +87,7 @@ return {
|
|||||||
disable = { 'missing-fields' },
|
disable = { 'missing-fields' },
|
||||||
},
|
},
|
||||||
format = {
|
format = {
|
||||||
enable = true,
|
enable = false,
|
||||||
defaultConfig = {
|
|
||||||
indent_style = 'space',
|
|
||||||
indent_size = '2',
|
|
||||||
quote_style = 'single',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -131,9 +130,7 @@ return {
|
|||||||
callback = function(args)
|
callback = function(args)
|
||||||
local bufnr = args.buf
|
local bufnr = args.buf
|
||||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||||
if not client then
|
if not client then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
lspKeys(client, bufnr)
|
lspKeys(client, bufnr)
|
||||||
|
|
||||||
if client.server_capabilities.completionProvider then
|
if client.server_capabilities.completionProvider then
|
||||||
@ -141,17 +138,6 @@ return {
|
|||||||
vim.bo[bufnr].formatexpr = 'v:lua.vim.lsp.formatexpr()'
|
vim.bo[bufnr].formatexpr = 'v:lua.vim.lsp.formatexpr()'
|
||||||
end
|
end
|
||||||
|
|
||||||
if client.server_capabilities.inlayHintProvider then
|
|
||||||
vim.keymap.set('n', '<space>i', function()
|
|
||||||
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr })
|
|
||||||
end, {
|
|
||||||
noremap = true,
|
|
||||||
silent = false,
|
|
||||||
desc = 'Toggle inlay hints',
|
|
||||||
buffer = bufnr,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
if client.server_capabilities.documentSymbolProvider then
|
if client.server_capabilities.documentSymbolProvider then
|
||||||
local navic = require('nvim-navic')
|
local navic = require('nvim-navic')
|
||||||
navic.attach(client, bufnr)
|
navic.attach(client, bufnr)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user