From fe9b851de8a197e627fe162a27235fdce5a3c36a Mon Sep 17 00:00:00 2001 From: Liam Dyer Date: Sat, 11 Jan 2025 12:22:50 -0500 Subject: [PATCH] feat: use health check for status command --- lua/blink/cmp/commands.lua | 34 +------------------------- lua/blink/cmp/health.lua | 50 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 35 deletions(-) diff --git a/lua/blink/cmp/commands.lua b/lua/blink/cmp/commands.lua index 546010a1..af8840f9 100644 --- a/lua/blink/cmp/commands.lua +++ b/lua/blink/cmp/commands.lua @@ -1,41 +1,9 @@ local commands = {} -function commands.status() - local sources = require('blink.cmp.sources.lib') - local all_providers = sources.get_all_providers() - local enabled_provider_ids = sources.get_enabled_provider_ids('default') - - --- @type string[] - local not_enabled_provider_ids = {} - for provider_id, _ in pairs(all_providers) do - if not vim.list_contains(enabled_provider_ids, provider_id) then - table.insert(not_enabled_provider_ids, provider_id) - end - end - - if #enabled_provider_ids > 0 then - vim.api.nvim_echo({ { '\n', 'Normal' } }, false, {}) - vim.api.nvim_echo({ { '# enabled sources providers\n', 'Special' } }, false, {}) - - for _, provider_id in ipairs(enabled_provider_ids) do - vim.api.nvim_echo({ { ('- %s\n'):format(provider_id), 'Normal' } }, false, {}) - end - end - - if #not_enabled_provider_ids > 0 then - vim.api.nvim_echo({ { '\n', 'Normal' } }, false, {}) - vim.api.nvim_echo({ { '# not enabled sources providers\n', 'Comment' } }, false, {}) - - for _, provider_id in pairs(not_enabled_provider_ids) do - vim.api.nvim_echo({ { ('- %s\n'):format(provider_id), 'Normal' } }, false, {}) - end - end -end - function commands.setup() vim.api.nvim_create_user_command('BlinkCmp', function(cmd) if cmd.fargs[1] == 'status' then - commands.status() + vim.cmd('checkhealth blink.cmp') else vim.notify("[blink.cmp] invalid command '" .. cmd.args .. "'", vim.log.levels.ERROR) end diff --git a/lua/blink/cmp/health.lua b/lua/blink/cmp/health.lua index d8ff4a12..8b731995 100644 --- a/lua/blink/cmp/health.lua +++ b/lua/blink/cmp/health.lua @@ -1,7 +1,7 @@ local health = {} -function health.check() - vim.health.start('blink.cmp healthcheck') +function health.report_system() + vim.health.start('System') local required_executables = { 'curl', 'git' } for _, executable in ipairs(required_executables) do @@ -32,4 +32,50 @@ function health.check() end end +function health.report_sources() + vim.health.start('Sources') + + local sources = require('blink.cmp.sources.lib') + + local all_providers = sources.get_all_providers() + local default_providers = sources.get_enabled_provider_ids('default') + local cmdline_providers = sources.get_enabled_provider_ids('cmdline') + + local bufnr = vim.api.nvim_create_buf(false, true) + vim.bo[bufnr].filetype = 'checkhealth' + + vim.health.warn('Some providers may show up as "disabled" but are enabled dynamically (i.e. cmdline)') + + --- @type string[] + local disabled_providers = {} + for provider_id, _ in pairs(all_providers) do + if + not vim.list_contains(default_providers, provider_id) and not vim.list_contains(cmdline_providers, provider_id) + then + table.insert(disabled_providers, provider_id) + end + end + + health.report_sources_list('Default sources', default_providers) + health.report_sources_list('Cmdline sources', cmdline_providers) + health.report_sources_list('Disabled sources', disabled_providers) +end + +--- @param header string +--- @param provider_ids string[] +function health.report_sources_list(header, provider_ids) + if #provider_ids == 0 then return end + + vim.health.start(header) + local all_providers = require('blink.cmp.sources.lib').get_all_providers() + for _, provider_id in ipairs(provider_ids) do + vim.health.info(('%s (%s)'):format(provider_id, all_providers[provider_id].config.module)) + end +end + +function health.check() + health.report_system() + health.report_sources() +end + return health