Skip to content

Commit

Permalink
feat: add checkhealth messages
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Jan 16, 2024
1 parent b2c644a commit c117933
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
27 changes: 27 additions & 0 deletions lua/dressing/health.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
local config = require("dressing.config")
local patch = require("dressing.patch")

local M = {}

-- The "report_" functions have been deprecated, so use the new ones if defined.
local health_start = vim.health.start or vim.health.report_start
local health_warn = vim.health.warn or vim.health.report_warn
local health_ok = vim.health.ok or vim.health.report_ok

M.check = function()
health_start("dressing.nvim")
if patch.is_enabled("input") then
health_ok("vim.ui.input active")
else
health_warn("vim.ui.input not enabled")
end

if patch.is_enabled("select") then
local _, name = require("dressing.select").get_backend(config.select.backend)
health_ok("vim.ui.select active: " .. name)
else
health_warn("vim.ui.select not enabled")
end
end

return M
16 changes: 11 additions & 5 deletions lua/dressing/patch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ end
local enabled_mods = {}
M.original_mods = {}

---@param key string
---@return boolean?
M.is_enabled = function(key)
local enabled = enabled_mods[key]
if enabled == nil then
enabled = require("dressing.config")[key].enabled
end
return enabled
end

for _, key in ipairs(all_modules) do
M.original_mods[key] = vim.ui[key]
vim.ui[key] = function(...)
local enabled = enabled_mods[key]
if enabled == nil then
enabled = require("dressing.config")[key].enabled
end
if enabled then
if M.is_enabled(key) then
require(string.format("dressing.%s", key))(...)
else
return M.original_mods[key](...)
Expand Down
20 changes: 16 additions & 4 deletions lua/dressing/select/init.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
local global_config = require("dressing.config")
local patch = require("dressing.patch")

local function get_backend(config)
local backends = config.backend
local M = {}

---@param backends string|string[]
---@return table select module
---@return string name of backend
M.get_backend = function(backends)
if type(backends) ~= "table" then
backends = { backends }
end
Expand All @@ -29,7 +33,7 @@ end
-- (see https://github.com/stevearc/dressing.nvim/issues/15)
-- also to prevent focus problems for providers
-- (see https://github.com/stevearc/dressing.nvim/issues/59)
return vim.schedule_wrap(function(items, opts, on_choice)
local select = vim.schedule_wrap(function(items, opts, on_choice)
vim.validate({
items = {
items,
Expand Down Expand Up @@ -64,7 +68,7 @@ return vim.schedule_wrap(function(items, opts, on_choice)
opts.format_item = sanitize_line
end

local backend, name = get_backend(config)
local backend, name = M.get_backend(config.backend)
local winid = vim.api.nvim_get_current_win()
local cursor = vim.api.nvim_win_get_cursor(winid)
backend.select(
Expand All @@ -79,3 +83,11 @@ return vim.schedule_wrap(function(items, opts, on_choice)
end)
)
end)

setmetatable(M, {
__call = function(_, ...)
return select(...)
end,
})

return M

0 comments on commit c117933

Please sign in to comment.