RFC: CmpStatus command (#210)
* Add `CmpStatus` command * Update headings * Fix heading * Update headings * Add README.md * Fix tests * Force invoke InsertEnter
This commit is contained in:
12
README.md
12
README.md
@@ -398,6 +398,14 @@ Specify whether to display ghost text.
|
||||
Default: `false`
|
||||
|
||||
|
||||
Commands
|
||||
====================
|
||||
|
||||
#### `CmpStatus`
|
||||
|
||||
Show the source statuses
|
||||
|
||||
|
||||
Programatic API
|
||||
====================
|
||||
|
||||
@@ -435,6 +443,10 @@ Scroll documentation window if possible.
|
||||
FAQ
|
||||
====================
|
||||
|
||||
#### I can't get the specific source working.
|
||||
|
||||
You should check `:CmpStatus` command's output. Probably, your specified source name is wrong.
|
||||
|
||||
#### What is the `pairs-wise plugin automatically supported`?
|
||||
|
||||
Some pairs-wise plugin set up the mapping automatically.
|
||||
|
||||
@@ -65,7 +65,7 @@ config.get_source_config = function(name)
|
||||
return s
|
||||
end
|
||||
end
|
||||
return {}
|
||||
return nil
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
@@ -110,6 +110,68 @@ cmp.confirm = function(option)
|
||||
end
|
||||
end
|
||||
|
||||
---Show status
|
||||
cmp.status = function()
|
||||
vim.cmd [[doautocmd InsertEnter]]
|
||||
|
||||
local kinds = {}
|
||||
kinds.available = {}
|
||||
kinds.unavailable = {}
|
||||
kinds.installed = {}
|
||||
kinds.invalid = {}
|
||||
local names = {}
|
||||
for _, s in pairs(core.sources) do
|
||||
names[s.name] = true
|
||||
|
||||
if config.get_source_config(s.name) then
|
||||
if s:is_available() then
|
||||
table.insert(kinds.available, s:get_debug_name())
|
||||
else
|
||||
table.insert(kinds.unavailable, s:get_debug_name())
|
||||
end
|
||||
else
|
||||
table.insert(kinds.installed, s:get_debug_name())
|
||||
end
|
||||
end
|
||||
for _, s in ipairs(config.get().sources) do
|
||||
if not names[s.name] then
|
||||
table.insert(kinds.invalid, s.name)
|
||||
end
|
||||
end
|
||||
|
||||
if #kinds.available > 0 then
|
||||
vim.api.nvim_echo({ { '\n', 'Normal' } }, false, {})
|
||||
vim.api.nvim_echo({ { '# ready source names\n', 'Special' } }, false, {})
|
||||
for _, name in ipairs(kinds.available) do
|
||||
vim.api.nvim_echo({ { ('- %s\n'):format(name), 'Normal' } }, false, {})
|
||||
end
|
||||
end
|
||||
|
||||
if #kinds.unavailable > 0 then
|
||||
vim.api.nvim_echo({ { '\n', 'Normal' } }, false, {})
|
||||
vim.api.nvim_echo({ { '# unavailable source names\n', 'Comment' } }, false, {})
|
||||
for _, name in ipairs(kinds.unavailable) do
|
||||
vim.api.nvim_echo({ { ('- %s\n'):format(name), 'Normal' } }, false, {})
|
||||
end
|
||||
end
|
||||
|
||||
if #kinds.installed > 0 then
|
||||
vim.api.nvim_echo({ { '\n', 'Normal' } }, false, {})
|
||||
vim.api.nvim_echo({ { '# unused source names\n', 'WarningMsg' } }, false, {})
|
||||
for _, name in ipairs(kinds.installed) do
|
||||
vim.api.nvim_echo({ { ('- %s\n'):format(name), 'Normal' } }, false, {})
|
||||
end
|
||||
end
|
||||
|
||||
if #kinds.invalid > 0 then
|
||||
vim.api.nvim_echo({ { '\n', 'Normal' } }, false, {})
|
||||
vim.api.nvim_echo({ { '# unknown source names\n', 'ErrorMsg' } }, false, {})
|
||||
for _, name in ipairs(kinds.invalid) do
|
||||
vim.api.nvim_echo({ { ('- %s\n'):format(name), 'Normal' } }, false, {})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@type cmp.Setup
|
||||
cmp.setup = setmetatable({
|
||||
global = function(c)
|
||||
|
||||
@@ -63,7 +63,7 @@ end
|
||||
---Return source option
|
||||
---@return cmp.SourceConfig
|
||||
source.get_config = function(self)
|
||||
return config.get_source_config(self.name)
|
||||
return config.get_source_config(self.name) or {}
|
||||
end
|
||||
|
||||
---Get fetching time
|
||||
@@ -175,7 +175,7 @@ source.get_debug_name = function(self)
|
||||
if self.source.get_debug_name then
|
||||
name = self.source:get_debug_name()
|
||||
end
|
||||
return name .. '(' .. self.id .. ')'
|
||||
return name
|
||||
end
|
||||
|
||||
---Return the source is available or not.
|
||||
|
||||
@@ -17,3 +17,5 @@ vim.cmd [[
|
||||
|
||||
vim.cmd [[inoremap <silent> <Plug>(cmp-autoindent) <C-o>:normal!==<CR>]]
|
||||
|
||||
vim.cmd [[command! CmpStatus lua require('cmp').status()]]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user