aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/nvim/.config/nvim/lua/tobyvin/lsp/handlers.lua
blob: cfd2f304f6b500fb5e2543e7fa195707672d9c5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
local M = {}

local handler_prehook = function(method, pre_hook, post_hook)
	local original = vim.lsp.handlers[method]
	vim.lsp.handlers[method] = function(...)
		if pre_hook ~= nil then
			pre_hook(...)
		end
		original(...)
		if post_hook ~= nil then
			post_hook(...)
		end
	end
end

M.setup = function()
	handler_prehook("textDocument/definition", function(_, result)
		if not result or vim.tbl_isempty(result) then
			vim.notify("[LSP] No definition found", "info")
		end
	end)

	handler_prehook("textDocument/implementation", function(_, result)
		if not result or vim.tbl_isempty(result) then
			vim.notify("[LSP] No implementations found", "info")
		end
	end)

	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["window/showMessage"] = function(_, result, ctx)
		vim.notify({ result.message }, 5 - result.type, {
			title = "[LSP] " .. vim.lsp.get_client_by_id(ctx.client_id),
		})
	end
end

return M