nvim: lsp: Enable code action only when supported

This commit is contained in:
Sanchayan Maity 2021-12-10 18:47:00 +05:30
parent 1891eef80a
commit 0fbd8d256e

View file

@ -119,11 +119,13 @@ local on_attach = function(client, bufnr)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'pd' , '<cmd>lua PeekDefinition()<CR>' , opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>k', '<cmd>lua vim.lsp.buf.hover()<CR>' , opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>S', '<cmd>lua vim.lsp.buf.signature_help()<CR>' , opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ga' , '<cmd>lua vim.lsp.buf.code_action()<CR>' , opts)
vim.api.nvim_buf_set_keymap(bufnr, 'v', 'ga' , '<cmd>lua vim.lsp.buf.range_code_action()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>r', '<cmd>lua vim.lsp.buf.code_action{ only = \'refactor\' }<CR>' , opts)
vim.api.nvim_buf_set_keymap(bufnr, 'v', '<Leader>r', '<cmd>lua vim.lsp.buf.range_code_action{ only = \'refactor\' }<CR>', opts)
if client.resolved_capabilities.code_action then
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ga' , '<cmd>lua vim.lsp.buf.code_action()<CR>' , opts)
vim.api.nvim_buf_set_keymap(bufnr, 'v', 'ga' , '<cmd>lua vim.lsp.buf.range_code_action()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>r', '<cmd>lua vim.lsp.buf.code_action{ only = \'refactor\' }<CR>' , opts)
vim.api.nvim_buf_set_keymap(bufnr, 'v', '<Leader>r', '<cmd>lua vim.lsp.buf.range_code_action{ only = \'refactor\' }<CR>', opts)
end
if client.resolved_capabilities.document_range_formatting then
vim.api.nvim_buf_set_keymap(bufnr, 'x', 'gq', '<cmd>lua FormatRangeOperator()<CR>', opts)