diff --git a/README.md b/README.md index e524f8a..1a27d80 100644 --- a/README.md +++ b/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. diff --git a/lua/cmp/config.lua b/lua/cmp/config.lua index ad63222..ff4c6f1 100644 --- a/lua/cmp/config.lua +++ b/lua/cmp/config.lua @@ -65,7 +65,7 @@ config.get_source_config = function(name) return s end end - return {} + return nil end) end diff --git a/lua/cmp/init.lua b/lua/cmp/init.lua index 6464199..05167f7 100644 --- a/lua/cmp/init.lua +++ b/lua/cmp/init.lua @@ -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) diff --git a/lua/cmp/source.lua b/lua/cmp/source.lua index 57fa9e2..b384558 100644 --- a/lua/cmp/source.lua +++ b/lua/cmp/source.lua @@ -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. diff --git a/plugin/cmp.lua b/plugin/cmp.lua index cd3ff13..374d3ff 100644 --- a/plugin/cmp.lua +++ b/plugin/cmp.lua @@ -17,3 +17,5 @@ vim.cmd [[ vim.cmd [[inoremap (cmp-autoindent) :normal!==]] +vim.cmd [[command! CmpStatus lua require('cmp').status()]] +