summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-11-10 17:25:01 -0600
committerToby Vincent <tobyv13@gmail.com>2022-11-10 17:25:01 -0600
commitbd9fa7a3e038cae892afeb90848a0c2c3cf760d1 (patch)
tree8b3fba73dd364e3907a59bee7875c0d99b12a037
parent6624ba73a04425dc5491ce1a8be9ea1d55d920a8 (diff)
refactor(lsp): fix lsp definition handler
-rw-r--r--nvim/.config/nvim/lua/tobyvin/lsp/handlers.lua54
1 files changed, 19 insertions, 35 deletions
diff --git a/nvim/.config/nvim/lua/tobyvin/lsp/handlers.lua b/nvim/.config/nvim/lua/tobyvin/lsp/handlers.lua
index a4f2f21..d3e5378 100644
--- a/nvim/.config/nvim/lua/tobyvin/lsp/handlers.lua
+++ b/nvim/.config/nvim/lua/tobyvin/lsp/handlers.lua
@@ -1,40 +1,29 @@
local utils = require("tobyvin.utils")
local M = {}
-M.wrap_handler = function(method, handler)
- handler = vim.F.if_nil(handler, vim.lsp.handlers[method])
- return function(err, result, ctx, config)
- if result == nil or vim.tbl_isempty(result) then
- vim.notify("No location found", vim.log.levels.INFO, { title = "[LSP] " .. ctx.method })
- return nil
- end
-
- if vim.tbl_islist(result) then
- result = result[1]
- end
- handler(err, result, ctx, config)
+local location_handler = vim.lsp.handlers["textDocument/definition"]
+local definition_handler = function(err, result, ctx, config)
+ if not result or vim.tbl_isempty(result) then
+ vim.notify("No location found", vim.log.levels.INFO, { title = "[LSP] " .. ctx.method })
+ elseif vim.tbl_islist(result) then
+ result = result[1]
end
-end
-
-M.setup = function()
- vim.lsp.handlers["textDocument/publishDiagnostics"] =
- vim.lsp.with(vim.lsp.handlers["textDocument/publishDiagnostics"], {
- signs = true,
- underline = true,
- update_in_insert = true,
- virtual_text = true,
- })
- vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "single" })
+ location_handler(err, result, ctx, config)
+end
- vim.lsp.handlers["textDocument/signatureHelp"] =
- vim.lsp.with(vim.lsp.handlers.signature_help, { border = "single" })
+local show_message = function(_, result, ctx)
+ vim.notify(result.message, 5 - result.type, {
+ title = "[LSP] " .. vim.lsp.get_client_by_id(ctx.client_id),
+ })
+end
- vim.lsp.handlers["window/showMessage"] = function(_, result, ctx)
- vim.notify(result.message, 5 - result.type, {
- title = "[LSP] " .. vim.lsp.get_client_by_id(ctx.client_id),
- })
- end
+M.setup = function()
+ local hover_ops = { border = "single" }
+ vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, hover_ops)
+ vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, hover_ops)
+ vim.lsp.handlers["textDocument/definition"] = definition_handler
+ vim.lsp.handlers["window/showMessage"] = show_message
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("tobyvin_lsp_handlers", { clear = true }),
@@ -42,11 +31,6 @@ M.setup = function()
callback = function(args)
local bufnr = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
-
- if client.name ~= "rust_analyzer" then
- vim.lsp.handlers["textDocument/definition"] = M.wrap_handler("textDocument/definition")
- end
-
if client.server_capabilities["definitionProvider"] then
vim.bo[bufnr].tagfunc = "v:lua.vim.lsp.tagfunc"
end