Skip to content

Commit

Permalink
fix: don't set what's set by default (formatexpr, tagfunc etc. and ho…
Browse files Browse the repository at this point in the history
…ver keymap)
  • Loading branch information
konradmalik committed Sep 22, 2023
1 parent c4d441c commit e174af4
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions config/native/lua/konrad/lsp/event_handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ local telescope = require("telescope.builtin")
local keymapper = require("konrad.lsp.keymapper")
local registry = require("konrad.lsp.registry")
local augroups = require("konrad.lsp.augroups")
local protocol = require("vim.lsp.protocol")
local ms = protocol.Methods

local M = {}

Expand All @@ -10,7 +12,7 @@ local M = {}
M.detach = function(client, bufnr)
augroups.del_autocmds_for_buf(client, bufnr)

if client.supports_method("textDocument/codeLens") then
if client.supports_method(ms.textDocument_codeLens) then
require("konrad.lsp.capability_handlers.codelens").detach()
end

Expand All @@ -33,69 +35,59 @@ M.attach = function(client, bufnr)
client = client,
}

if client.supports_method("textDocument/codeAction") then
if client.supports_method(ms.textDocument_codeAction) then
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts_with_desc("Code Action"))
end

if client.supports_method("textDocument/codeLens") then
if client.supports_method(ms.codeLens_resolve) then
registry.register_once("CodeLens", register_data, require("konrad.lsp.capability_handlers.codelens").attach)
end

if client.supports_method("textDocument/completion") then
-- Enable completion triggered by <c-x><c-o>
vim.bo[bufnr].omnifunc = "v:lua.vim.lsp.omnifunc"
end

if client.supports_method("textDocument/formatting") then
if client.supports_method(ms.textDocument_formatting) then
registry.register_once("Formatting", register_data, require("konrad.lsp.capability_handlers.format").setup)
end

if client.supports_method("textDocument/declaration") then
if client.supports_method(ms.textDocument_declaration) then
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts_with_desc("Go To Declaration"))
end

if client.supports_method("textDocument/definition") then
vim.bo[bufnr].tagfunc = "v:lua.vim.lsp.tagfunc"
if client.supports_method(ms.textDocument_definition) then
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts_with_desc("Go To Definition"))
vim.keymap.set("n", "<leader>fd", telescope.lsp_definitions, opts_with_desc("Telescope [D]efinitions"))
end

if client.supports_method("textDocument/documentHighlight") then
if client.supports_method(ms.textDocument_documentHighlight) then
registry.register_once(
"DocumentHighlighting",
register_data,
require("konrad.lsp.capability_handlers.documenthighlight").setup
)
end

if client.supports_method("textDocument/documentSymbol") then
if client.supports_method(ms.textDocument_documentSymbol) then
registry.register_once("Navic", register_data, require("konrad.lsp.capability_handlers.navic").setup)
end

if client.supports_method("textDocument/hover") then
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts_with_desc("Hover"))
end

if client.supports_method("textDocument/implementation") then
if client.supports_method(ms.textDocument_implementation) then
vim.keymap.set("n", "gp", vim.lsp.buf.implementation, opts_with_desc("Go To Implementation"))
vim.keymap.set("n", "<leader>fp", telescope.lsp_implementations, opts_with_desc("Telescope Im[p]lementations"))
end

if client.supports_method("textDocument/references") then
if client.supports_method(ms.textDocument_references) then
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts_with_desc("References"))
vim.keymap.set("n", "<leader>fr", telescope.lsp_references, opts_with_desc("Telescope [R]eferences"))
end

if client.supports_method("textDocument/rename") then
if client.supports_method(ms.textDocument_rename) then
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts_with_desc("Rename"))
end

if client.supports_method("textDocument/signatureHelp") then
if client.supports_method(ms.textDocument_signatureHelp) then
vim.keymap.set("n", "gs", vim.lsp.buf.signature_help, opts_with_desc("Signature Help"))
vim.keymap.set("i", "<c-s>", vim.lsp.buf.signature_help, opts_with_desc("Signature Help"))
end

if client.supports_method("textDocument/typeDefinition") then
if client.supports_method(ms.textDocument_typeDefinition) then
vim.keymap.set("n", "gT", vim.lsp.buf.type_definition, opts_with_desc("Go To Type Definition"))
vim.keymap.set(
"n",
Expand All @@ -105,7 +97,7 @@ M.attach = function(client, bufnr)
)
end

if client.supports_method("workspaceSymbol/resolve") then
if client.supports_method(ms.workspaceSymbol_resolve) then
vim.keymap.set("n", "<leader>ws", vim.lsp.buf.workspace_symbol, opts_with_desc("Search workspace symbols"))
vim.keymap.set(
"n",
Expand All @@ -115,7 +107,7 @@ M.attach = function(client, bufnr)
)
end

if client.supports_method("textDocument/inlayHint") then
if client.supports_method(ms.textDocument_inlayHint) then
registry.register_once("InlayHints", register_data, require("konrad.lsp.capability_handlers.inlayhints").attach)
end

Expand Down

0 comments on commit e174af4

Please sign in to comment.