Skip to content

Commit

Permalink
feat: added health checks to see if other plugins have overwritten No…
Browse files Browse the repository at this point in the history
…ice handlers
  • Loading branch information
folke committed Oct 26, 2022
1 parent 4a46ba3 commit 906c6c8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
37 changes: 34 additions & 3 deletions lua/noice/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local require = require("noice.util.lazy")

local Util = require("noice.util")
local Config = require("noice.config")
local Lsp = require("noice.source.lsp")

local M = {}

Expand Down Expand Up @@ -117,10 +118,40 @@ function M.check(opts)
end

if Config.is_running() then
if Config.options.notify.enabled and vim.notify ~= require("noice.source.notify").notify then
log.error("`vim.notify` has been overwritten by another plugin?")
if Config.options.notify.enabled then
if vim.notify ~= require("noice.source.notify").notify then
log.error("`vim.notify` has been overwritten by another plugin?")
else
log.ok("`vim.notify` is set to **Noice**")
end
else
if opts.checkhealth then
log.warn("Noice `vim.notify` is disabled")
end
end

if Config.options.lsp.hover.enabled then
if vim.lsp.handlers["textDocument/hover"] ~= Lsp.hover then
log.error([[`vim.lsp.handlers["textDocument/hover"]` has been overwritten by another plugin?]])
else
log.ok([[`vim.lsp.handlers["textDocument/hover"]` is handled by **Noice**]])
end
else
log.ok("`vim.notify` is set to **Noice**")
if opts.checkhealth then
log.warn([[`vim.lsp.handlers["textDocument/hover"]` is not handled by **Noice**]])
end
end

if Config.options.lsp.signature.enabled then
if vim.lsp.handlers["textDocument/signatureHelp"] ~= Lsp.signature then
log.error([[`vim.lsp.handlers["textDocument/signatureHelp"]` has been overwritten by another plugin?]])
else
log.ok([[`vim.lsp.handlers["textDocument/signatureHelp"]` is handled by **Noice**]])
end
else
if opts.checkhealth then
log.warn([[`vim.lsp.handlers["textDocument/signatureHelp"]` is not handled by **Noice**]])
end
end
end

Expand Down
10 changes: 7 additions & 3 deletions lua/noice/source/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ function M.get(kind)
end

function M.setup()
-- vim.api.nvim_win_get_option(win,
M.hover = Util.protect(M.hover)
if Config.options.lsp.hover.enabled then
vim.lsp.handlers["textDocument/hover"] = Util.protect(M.hover)
vim.lsp.handlers["textDocument/hover"] = M.hover
end

M.signature = Util.protect(M.signature)
if Config.options.lsp.signature.enabled then
vim.lsp.handlers["textDocument/signatureHelp"] = Util.protect(M.signature)
vim.lsp.handlers["textDocument/signatureHelp"] = M.signature
end

if Config.options.lsp.signature.auto_open then
require("noice.source.lsp.signature").setup()
end

if Config.options.lsp.progress.enabled then
require("noice.source.lsp.progress").setup()
end
Expand Down
2 changes: 1 addition & 1 deletion lua/noice/text/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function M.keys(buf)
local pos = vim.api.nvim_win_get_cursor(0)
local col = pos[2] + 1

for pattern, handler in pairs(require("noice.config").options.markdown.hover) do
for pattern, handler in pairs(Config.options.markdown.hover) do
local from = 1
local to, url
while from do
Expand Down

0 comments on commit 906c6c8

Please sign in to comment.