Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
100 lines
3.4 KiB
Lua
100 lines
3.4 KiB
Lua
local kit = require('cmp_dictionary.kit')
|
|
local Cache = require('cmp_dictionary.kit.App.Cache')
|
|
|
|
---@class cmp_dictionary.kit.App.Config.Schema
|
|
|
|
---@alias cmp_dictionary.kit.App.Config.SchemaInternal cmp_dictionary.kit.App.Config.Schema|{ revision: integer }
|
|
|
|
---@class cmp_dictionary.kit.App.Config
|
|
---@field private _cache cmp_dictionary.kit.App.Cache
|
|
---@field private _default cmp_dictionary.kit.App.Config.SchemaInternal
|
|
---@field private _global cmp_dictionary.kit.App.Config.SchemaInternal
|
|
---@field private _filetype table<string, cmp_dictionary.kit.App.Config.SchemaInternal>
|
|
---@field private _buffer table<integer, cmp_dictionary.kit.App.Config.SchemaInternal>
|
|
local Config = {}
|
|
Config.__index = Config
|
|
|
|
---Create new config instance.
|
|
---@param default cmp_dictionary.kit.App.Config.Schema
|
|
function Config.new(default)
|
|
local self = setmetatable({}, Config)
|
|
self._cache = Cache.new()
|
|
self._default = default
|
|
self._global = {}
|
|
self._filetype = {}
|
|
self._buffer = {}
|
|
return self
|
|
end
|
|
|
|
---Update global config.
|
|
---@param config cmp_dictionary.kit.App.Config.Schema
|
|
function Config:global(config)
|
|
local revision = (self._global.revision or 1) + 1
|
|
self._global = config or {}
|
|
self._global.revision = revision
|
|
end
|
|
|
|
---Update filetype config.
|
|
---@param filetypes string|string[]
|
|
---@param config cmp_dictionary.kit.App.Config.Schema
|
|
function Config:filetype(filetypes, config)
|
|
for _, filetype in ipairs(kit.to_array(filetypes)) do
|
|
local revision = ((self._filetype[filetype] or {}).revision or 1) + 1
|
|
self._filetype[filetype] = config or {}
|
|
self._filetype[filetype].revision = revision
|
|
end
|
|
end
|
|
|
|
---Update filetype config.
|
|
---@param bufnr integer
|
|
---@param config cmp_dictionary.kit.App.Config.Schema
|
|
function Config:buffer(bufnr, config)
|
|
bufnr = bufnr == 0 and vim.api.nvim_get_current_buf() or bufnr
|
|
local revision = ((self._buffer[bufnr] or {}).revision or 1) + 1
|
|
self._buffer[bufnr] = config or {}
|
|
self._buffer[bufnr].revision = revision
|
|
end
|
|
|
|
---Get current configuration.
|
|
---@return cmp_dictionary.kit.App.Config.Schema
|
|
function Config:get()
|
|
local filetype = vim.api.nvim_buf_get_option(0, 'filetype')
|
|
local bufnr = vim.api.nvim_get_current_buf()
|
|
return self._cache:ensure({
|
|
tostring(self._global.revision or 0),
|
|
tostring((self._buffer[bufnr] or {}).revision or 0),
|
|
tostring((self._filetype[filetype] or {}).revision or 0),
|
|
}, function()
|
|
local config = self._default
|
|
config = kit.merge(self._global, config)
|
|
config = kit.merge(self._filetype[filetype] or {}, config)
|
|
config = kit.merge(self._buffer[bufnr] or {}, config)
|
|
config.revision = nil
|
|
return config
|
|
end)
|
|
end
|
|
|
|
---Create setup interface.
|
|
---@return fun(config: cmp_dictionary.kit.App.Config.Schema)|{ filetype: fun(filetypes: string|string[], config: cmp_dictionary.kit.App.Config.Schema), buffer: fun(bufnr: integer, config: cmp_dictionary.kit.App.Config.Schema) }
|
|
function Config:create_setup_interface()
|
|
return setmetatable({
|
|
---@param filetypes string|string[]
|
|
---@param config cmp_dictionary.kit.App.Config.Schema
|
|
filetype = function(filetypes, config)
|
|
self:filetype(filetypes, config)
|
|
end,
|
|
---@param bufnr integer
|
|
---@param config cmp_dictionary.kit.App.Config.Schema
|
|
buffer = function(bufnr, config)
|
|
self:buffer(bufnr, config)
|
|
end,
|
|
}, {
|
|
---@param config cmp_dictionary.kit.App.Config.Schema
|
|
__call = function(_, config)
|
|
self:global(config)
|
|
end,
|
|
})
|
|
end
|
|
|
|
return Config
|