79 lines
3.4 KiB
Lua
79 lines
3.4 KiB
Lua
local M = {}
|
|
|
|
M._keys = nil
|
|
|
|
function M.get()
|
|
local format = function()
|
|
require('user.plugins.lsp.lspconfig.format').format()
|
|
end
|
|
|
|
if not M._keys then
|
|
M._keys = {
|
|
{ '<leader>le', vim.diagnostic.open_float, desc = 'Line diagnostic' },
|
|
{ '<leader>lf', format, desc = 'Format document', has = 'documentFormatting' },
|
|
{ '<leader>lf', format, desc = 'Format range', mode = 'x', has = 'documentRangeFormatting' },
|
|
{ '<leader>la', vim.lsp.buf.code_action, desc = 'Code action', mode = { 'n', 'x' }, has = 'codeAction' },
|
|
{ '<leader>ll', vim.lsp.codelens.run, desc = 'Codelens action', mode = 'n', has = 'codeLens' },
|
|
{ '<leader>ld', '<cmd>Trouble document_diagnostics<CR>', desc = 'Document diagnostics' },
|
|
{ '<leader>lw', '<cmd>Trouble workspace_diagnostics<CR>', desc = 'Workspace diagnostics' },
|
|
|
|
{ 'gd', '<cmd>Trouble lsp_definitions<CR>', desc = 'Goto definition', has = 'definition' },
|
|
{ 'gr', '<cmd>Trouble lsp_references<CR>', desc = 'References' },
|
|
{ 'gD', vim.lsp.buf.declaration, desc = 'Goto declaration' },
|
|
{ 'gI', '<cmd>Trouble lsp_implementations<CR>', desc = 'Goto implementation' },
|
|
{ 'gy', '<cmd>Trouble lsp_type_definitions<CR>', desc = 'Goto type definition' },
|
|
{ 'K', vim.lsp.buf.hover, desc = 'Hover' },
|
|
{ 'gK', vim.lsp.buf.signature_help, desc = 'Signature help', has = 'signatureHelp' },
|
|
{ '<c-k>', vim.lsp.buf.signature_help, mode = 'i', desc = 'Signature help', has = 'signatureHelp' },
|
|
{ ']d', M.diagnostic_goto(true), desc = 'Next diagnostic' },
|
|
{ '[d', M.diagnostic_goto(false), desc = 'Previous diagnostic' },
|
|
{ ']e', M.diagnostic_goto(true, 'ERROR'), desc = 'Next error' },
|
|
{ '[e', M.diagnostic_goto(false, 'ERROR'), desc = 'Previous error' },
|
|
{ ']w', M.diagnostic_goto(true, 'WARN'), desc = 'Next warning' },
|
|
{ '[w', M.diagnostic_goto(false, 'WARN'), desc = 'Previous warning' },
|
|
}
|
|
|
|
if require('user.util.misc').has('inc-rename.nvim') then
|
|
M._keys[#M._keys + 1] = {
|
|
'<leader>lr',
|
|
function()
|
|
local inc_rename = require('inc_rename')
|
|
return ':' .. inc_rename.config.cmd_name .. ' ' .. vim.fn.expand('<cword>')
|
|
end,
|
|
expr = true,
|
|
desc = 'Rename',
|
|
has = 'rename',
|
|
}
|
|
else
|
|
M._keys[#M._keys + 1] = { '<leader>lr', vim.lsp.buf.rename, desc = 'Rename', has = 'rename' }
|
|
end
|
|
end
|
|
return M._keys
|
|
end
|
|
|
|
function M.on_attach(client, buffer)
|
|
local Keys = require('lazy.core.handler.keys')
|
|
local keymaps = Keys.resolve(M.get())
|
|
|
|
for _, keys in pairs(keymaps) do
|
|
local method = keys.has
|
|
if not keys.has or client.supports_method(method:find('/') and method or 'textDocument/' .. method) then
|
|
local opts = Keys.opts(keys)
|
|
opts.has = nil
|
|
opts.silent = opts.silent ~= false
|
|
opts.buffer = buffer
|
|
vim.keymap.set(keys.mode or 'n', keys.lhs, keys.rhs, opts)
|
|
end
|
|
end
|
|
end
|
|
|
|
function M.diagnostic_goto(next, severity)
|
|
local go = next and vim.diagnostic.goto_next or vim.diagnostic.goto_prev
|
|
severity = severity and vim.diagnostic.severity[severity] or nil
|
|
return function()
|
|
go { severity = severity }
|
|
end
|
|
end
|
|
|
|
return M
|