Improve vim source

This commit is contained in:
hrsh7th
2021-09-14 01:16:49 +09:00
parent 6173796b2b
commit 03f121fa23
3 changed files with 11 additions and 15 deletions

View File

@@ -47,9 +47,9 @@ endfunction
"
" cmp#_method
"
function! cmp#_method(id, method, args) abort
function! cmp#_method(bridge_id, method, args) abort
try
let l:source = s:sources[a:id]
let l:source = s:sources[a:bridge_id]
if a:method ==# 'is_available'
return l:source[a:method]()
elseif a:method ==# 'get_debug_name'

View File

@@ -72,9 +72,6 @@ end
---@type table<number, cmp.Source>
core.sources = {}
---@type table<string, cmp.Source>
core.sources_by_name = {}
---@type cmp.Context
core.context = context.new()
@@ -82,13 +79,11 @@ core.context = context.new()
---@param s cmp.Source
core.register_source = function(s)
core.sources[s.id] = s
core.sources_by_name[s.name] = s
end
---Unregister source
---@param source_id string
core.unregister_source = function(source_id)
core.sources_by_name[core.sources[source_id]] = nil
core.sources[source_id] = nil
end
@@ -123,11 +118,12 @@ end
core.get_sources = function(statuses)
local sources = {}
for _, c in pairs(config.get().sources) do
local s = core.sources_by_name[c.name]
if s then
if not statuses or vim.tbl_contains(statuses, s.status) then
if s:is_available() then
table.insert(sources, s)
for _, s in pairs(core.sources) do
if c.name == s.name then
if not statuses or vim.tbl_contains(statuses, s.status) then
if s:is_available() then
table.insert(sources, s)
end
end
end
end

View File

@@ -36,12 +36,12 @@ end
---@param id number
---@param methods string[]
vim_source.new = function (id, methods)
local self = setmetatable({}, { __index = vim_source })
vim_source.new = function (bridge_id, methods)
local self = {}
for _, method in ipairs(methods) do
self[method] = (function(m)
return function(_, ...)
return vim.fn['cmp#_method'](id, m, vim_source.to_args({ ... }))
return vim.fn['cmp#_method'](bridge_id, m, vim_source.to_args({ ... }))
end
end)(method)
end