local M = {} local Methods = vim.lsp.protocol.Methods function M.on_attach(client, bufnr) if client:supports_method(Methods.textDocument_hover) then bmap({ 'n', 'K', vim.lsp.buf.hover }) end if client:supports_method(Methods.textDocument_documentSymbol) then local ok, navic = pcall(require, 'nvim-navic') if ok then navic.attach(client, bufnr) end end local ok, _ = pcall(require, 'fzf-lua') local mappings = { { Methods.textDocument_codeAction, 'gra', ok and 'FzfLua lsp_code_actions' or vim.lsp.buf.code_action, }, { Methods.textDocument_declaration, 'gD', ok and 'FzfLua lsp_declarations' or vim.lsp.buf.declaration, }, { Methods.textDocument_definition, 'gd', ok and 'FzfLua lsp_definitions' or vim.lsp.buf.definition, }, { Methods.textDocument_implementation, 'gri', ok and 'FzfLua lsp_implementations' or vim.lsp.buf.implementation, }, { Methods.textDocument_references, 'grr', ok and 'FzfLua lsp_references' or vim.lsp.buf.references, }, { Methods.textDocument_typeDefinition, 'grt', ok and 'FzfLua lsp_typedefs' or vim.lsp.buf.type_definition, }, { Methods.textDocument_documentSymbol, 'gs', ok and 'FzfLua lsp_document_symbols' or vim.lsp.buf.document_symbol, }, { Methods.workspace_diagnostic, 'gw', ok and 'FzfLua lsp_workspace_diagnostics' or vim.diagnostic.setqflist, }, { Methods.workspace_symbol, 'gS', ok and 'FzfLua lsp_workspace_symbols' or vim.lsp.buf.workspace_symbol, }, } for _, m in ipairs(mappings) do local method, key, cmd = unpack(m) if client:supports_method(method) then bmap({ 'n', key, cmd }) end end end function M.format() if pcall(require, 'guard.filetype') then vim.cmd.Guard('fmt') else vim.lsp.buf.format({ async = true }) end end return M