Skip to content

Commit

Permalink
feat: add BlinkCmp status command (#809)
Browse files Browse the repository at this point in the history
* feat: add `BlinkCmpStatus` command

The command `:BlinkCmpStatus` can be used to view which sources
providers are enabled or not enabled.

This is inspired by and implemented based on the `:CmpStatus` command
from `hrsh7th/nvim-cmp`.

* refactor: move BlinkCmpStatus to top level commands.lua

* refactor: move BlinkCmpStatus into top-level command BlinkCmp

With this commit the `:BlinkCmpStatus` command is removed and replaced
with the `:BlinkCmp status` command.
  • Loading branch information
bydlw98 authored Jan 11, 2025
1 parent 64cb887 commit 86c9676
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/configuration/sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ sources.providers.lsp = {

Blink can use `nvim-cmp` sources through a compatibility layer developed by [stefanboca](https://github.com/stefanboca): [blink.compat](https://github.com/Saghen/blink.compat). Please open any issues with `blink.compat` in that repo

## Checking status of sources providers

The command `:BlinkCmp status` can be used to view which sources providers are enabled or not enabled.

## Community sources

- [lazydev](https://github.com/folke/lazydev.nvim)
Expand Down
45 changes: 45 additions & 0 deletions lua/blink/cmp/commands.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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()
else
vim.notify("[blink.cmp] invalid command '" .. cmd.args .. "'", vim.log.levels.ERROR)
end
end, { nargs = 1, complete = function() return { 'status' } end, desc = 'blink.cmp' })
end

return commands
3 changes: 2 additions & 1 deletion lua/blink/cmp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ function cmp.setup(opts)
require('blink.cmp.fuzzy.download').ensure_downloaded(function(err)
if err then vim.notify(err, vim.log.levels.ERROR) end

-- setup highlights, keymap, completion and signature help
-- setup highlights, keymap, completion, commands and signature help
require('blink.cmp.highlights').setup()
require('blink.cmp.keymap').setup()
require('blink.cmp.completion').setup()
require("blink.cmp.commands").setup()
if config.signature.enabled then require('blink.cmp.signature').setup() end
end)
end
Expand Down

0 comments on commit 86c9676

Please sign in to comment.