2020-04-22 11:13:05 +02:00
|
|
|
local api = vim.api
|
2020-05-08 11:22:59 +02:00
|
|
|
|
2020-04-22 11:13:05 +02:00
|
|
|
local queries = require'nvim-treesitter.query'
|
2020-06-19 13:45:33 +02:00
|
|
|
local parsers = require'nvim-treesitter.parsers'
|
2020-06-25 13:26:31 -05:00
|
|
|
local utils = require'nvim-treesitter.utils'
|
2020-08-21 07:49:06 -05:00
|
|
|
local caching = require'nvim-treesitter.caching'
|
2020-05-08 11:22:59 +02:00
|
|
|
|
2020-06-21 20:38:00 +02:00
|
|
|
local M = {}
|
|
|
|
|
|
2020-04-22 11:13:05 +02:00
|
|
|
local config = {
|
2020-07-02 10:26:53 -05:00
|
|
|
modules = {},
|
2020-08-26 21:05:27 +02:00
|
|
|
ensure_installed = {},
|
|
|
|
|
update_strategy = 'lockfile',
|
2020-07-02 10:26:53 -05:00
|
|
|
}
|
|
|
|
|
-- List of modules that need to be setup on initialization.
|
|
|
|
|
local queued_modules_defs = {}
|
|
|
|
|
-- Whether we've initialized the plugin yet.
|
|
|
|
|
local is_initialized = false
|
|
|
|
|
local builtin_modules = {
|
|
|
|
|
highlight = {
|
|
|
|
|
module_path = 'nvim-treesitter.highlight',
|
|
|
|
|
enable = false,
|
2020-10-22 10:27:44 +02:00
|
|
|
disable = {'markdown'}, -- FIXME(vigoux): markdown highlighting breaks everything for now
|
2020-07-12 14:51:11 +02:00
|
|
|
custom_captures = {},
|
2020-07-02 10:26:53 -05:00
|
|
|
is_supported = queries.has_highlights
|
|
|
|
|
},
|
|
|
|
|
incremental_selection = {
|
|
|
|
|
module_path = 'nvim-treesitter.incremental_selection',
|
|
|
|
|
enable = false,
|
|
|
|
|
disable = {},
|
|
|
|
|
keymaps = {
|
|
|
|
|
init_selection="gnn",
|
|
|
|
|
node_incremental="grn",
|
|
|
|
|
scope_incremental="grc",
|
|
|
|
|
node_decremental="grm"
|
|
|
|
|
},
|
|
|
|
|
is_supported = queries.has_locals
|
|
|
|
|
},
|
2020-10-13 01:02:30 +02:00
|
|
|
indent = {
|
|
|
|
|
module_path = 'nvim-treesitter.indent',
|
|
|
|
|
enable = false,
|
|
|
|
|
disable = {},
|
2020-10-13 23:55:37 +02:00
|
|
|
is_supported = queries.has_indents
|
2020-10-13 01:02:30 +02:00
|
|
|
}
|
2020-04-22 11:13:05 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-21 07:49:06 -05:00
|
|
|
local attached_buffers_by_module = caching.create_buffer_cache()
|
|
|
|
|
|
2020-07-02 10:26:53 -05:00
|
|
|
-- Resolves a module by requiring the `module_path` or using the module definition.
|
|
|
|
|
local function resolve_module(mod_name)
|
|
|
|
|
local config_mod = M.get_module(mod_name)
|
|
|
|
|
|
|
|
|
|
if not config_mod then return end
|
|
|
|
|
|
|
|
|
|
if type(config_mod.attach) == 'function' and type(config_mod.detach) == 'function' then
|
|
|
|
|
return config_mod
|
|
|
|
|
elseif type(config_mod.module_path) == 'string' then
|
|
|
|
|
return require(config_mod.module_path)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-09-09 23:20:09 -05:00
|
|
|
-- Enables and attaches the module to a buffer for lang.
|
|
|
|
|
-- @param mod path to module
|
|
|
|
|
-- @param bufnr buffer number, defaults to current buffer
|
|
|
|
|
-- @param lang language, defaults to current language
|
2020-06-20 12:21:42 +02:00
|
|
|
local function enable_module(mod, bufnr, lang)
|
2020-04-22 11:13:05 +02:00
|
|
|
local bufnr = bufnr or api.nvim_get_current_buf()
|
2020-07-10 21:47:50 +02:00
|
|
|
local lang = lang or parsers.get_buf_lang(bufnr)
|
2020-07-02 10:26:53 -05:00
|
|
|
M.attach_module(mod, bufnr, lang)
|
2020-04-22 11:13:05 +02:00
|
|
|
end
|
|
|
|
|
|
2020-09-09 23:20:09 -05:00
|
|
|
-- Enables autocomands for the module.
|
|
|
|
|
-- After the module is loaded `loaded` will be set to true for the module.
|
|
|
|
|
-- @param mod path to module
|
|
|
|
|
local function enable_mod_conf_autocmd(mod)
|
2020-06-25 13:26:31 -05:00
|
|
|
local config_mod = M.get_module(mod)
|
2020-09-09 23:20:09 -05:00
|
|
|
if not config_mod or config_mod.loaded then
|
|
|
|
|
return
|
|
|
|
|
end
|
2020-04-22 11:13:05 +02:00
|
|
|
|
2020-07-02 10:26:53 -05:00
|
|
|
local cmd = string.format("lua require'nvim-treesitter.configs'.attach_module('%s')", mod)
|
2020-09-09 23:20:09 -05:00
|
|
|
api.nvim_command(string.format("autocmd NvimTreesitter FileType * %s", cmd))
|
2020-04-22 11:13:05 +02:00
|
|
|
|
2020-09-09 23:20:09 -05:00
|
|
|
config_mod.loaded = true
|
|
|
|
|
end
|
2020-08-30 21:06:09 +02:00
|
|
|
|
2020-09-09 23:20:09 -05:00
|
|
|
-- Enables the module globally and for all current buffers.
|
|
|
|
|
-- After enabled, `enable` will be set to true for the module.
|
|
|
|
|
-- @param mod path to module
|
|
|
|
|
local function enable_all(mod)
|
2020-06-25 13:26:31 -05:00
|
|
|
local config_mod = M.get_module(mod)
|
2020-09-10 17:57:19 -05:00
|
|
|
if not config_mod then return end
|
2020-04-22 11:13:05 +02:00
|
|
|
|
|
|
|
|
for _, bufnr in pairs(api.nvim_list_bufs()) do
|
2020-09-09 23:20:09 -05:00
|
|
|
enable_module(mod, bufnr)
|
2020-04-22 11:13:05 +02:00
|
|
|
end
|
2020-09-09 23:20:09 -05:00
|
|
|
|
|
|
|
|
enable_mod_conf_autocmd(mod)
|
2020-06-25 13:26:31 -05:00
|
|
|
config_mod.enable = true
|
2020-04-22 11:13:05 +02:00
|
|
|
end
|
|
|
|
|
|
2020-09-09 23:20:09 -05:00
|
|
|
-- Disables and detaches the module for a buffer.
|
|
|
|
|
-- @param mod path to module
|
|
|
|
|
-- @param bufnr buffer number, defaults to current buffer
|
|
|
|
|
local function disable_module(mod, bufnr)
|
2020-04-22 11:13:05 +02:00
|
|
|
local bufnr = bufnr or api.nvim_get_current_buf()
|
2020-07-02 10:26:53 -05:00
|
|
|
M.detach_module(mod, bufnr)
|
2020-04-22 11:13:05 +02:00
|
|
|
end
|
|
|
|
|
|
2020-09-09 23:20:09 -05:00
|
|
|
-- Disables autocomands for the module.
|
|
|
|
|
-- After the module is unloaded `loaded` will be set to false for the module.
|
|
|
|
|
-- @param mod path to module
|
|
|
|
|
local function disable_mod_conf_autocmd(mod)
|
2020-06-25 13:26:31 -05:00
|
|
|
local config_mod = M.get_module(mod)
|
2020-09-09 23:20:09 -05:00
|
|
|
if not config_mod or not config_mod.loaded then
|
|
|
|
|
return
|
2020-06-29 14:46:25 +02:00
|
|
|
end
|
2020-09-09 23:20:09 -05:00
|
|
|
-- TODO(kyazdani): detach the correct autocmd... doesn't work when using %s, cmd.
|
|
|
|
|
-- This will remove all autocomands!
|
|
|
|
|
api.nvim_command("autocmd! NvimTreesitter FileType *")
|
|
|
|
|
config_mod.loaded = false
|
2020-04-22 11:13:05 +02:00
|
|
|
end
|
|
|
|
|
|
2020-09-09 23:20:09 -05:00
|
|
|
-- Disables the module globally and for all current buffers.
|
|
|
|
|
-- After disabled, `enable` will be set to false for the module.
|
|
|
|
|
-- @param mod path to module
|
|
|
|
|
local function disable_all(mod)
|
|
|
|
|
local config_mod = M.get_module(mod)
|
|
|
|
|
if not config_mod or not config_mod.enable then return end
|
|
|
|
|
|
2020-04-22 11:13:05 +02:00
|
|
|
for _, bufnr in pairs(api.nvim_list_bufs()) do
|
2020-09-09 23:20:09 -05:00
|
|
|
disable_module(mod, bufnr)
|
2020-04-22 11:13:05 +02:00
|
|
|
end
|
2020-06-25 13:26:31 -05:00
|
|
|
|
2020-09-09 23:20:09 -05:00
|
|
|
disable_mod_conf_autocmd(mod)
|
|
|
|
|
config_mod.enable = false
|
2020-06-25 13:26:31 -05:00
|
|
|
end
|
|
|
|
|
|
2020-07-02 10:26:53 -05:00
|
|
|
-- Recurses through all modules including submodules
|
2020-06-25 13:26:31 -05:00
|
|
|
-- @param accumulator function called for each module
|
|
|
|
|
-- @param root root configuration table to start at
|
|
|
|
|
-- @param path prefix path
|
|
|
|
|
local function recurse_modules(accumulator, root, path)
|
|
|
|
|
local root = root or config.modules
|
|
|
|
|
|
|
|
|
|
for name, module in pairs(root) do
|
|
|
|
|
local new_path = path and (path..'.'..name) or name
|
|
|
|
|
|
|
|
|
|
if M.is_module(module) then
|
2020-07-02 10:26:53 -05:00
|
|
|
accumulator(name, module, new_path, root)
|
2020-06-25 13:26:31 -05:00
|
|
|
elseif type(module) == 'table' then
|
|
|
|
|
recurse_modules(accumulator, module, new_path)
|
|
|
|
|
end
|
2020-04-22 11:13:05 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-09-23 20:19:03 +02:00
|
|
|
-- Shows current configuration of all nvim-treesitter modules
|
|
|
|
|
-- @param process_function function used as the `process` parameter
|
|
|
|
|
-- for vim.inspect (https://github.com/kikito/inspect.lua#optionsprocess)
|
|
|
|
|
local function config_info(process_function)
|
|
|
|
|
process_function = process_function or function(item, path)
|
|
|
|
|
if path[#path] == vim.inspect.METATABLE then return end
|
|
|
|
|
if path[#path] == "is_supported" then return end
|
|
|
|
|
return item
|
|
|
|
|
end
|
|
|
|
|
print(vim.inspect(config, {process = process_function}))
|
|
|
|
|
end
|
|
|
|
|
|
2020-04-22 11:13:05 +02:00
|
|
|
M.commands = {
|
|
|
|
|
TSBufEnable = {
|
|
|
|
|
run = enable_module,
|
|
|
|
|
args = {
|
|
|
|
|
"-nargs=1",
|
2020-09-05 10:20:31 -05:00
|
|
|
"-complete=custom,nvim_treesitter#available_modules",
|
2020-09-04 12:44:19 -05:00
|
|
|
},
|
2020-04-22 11:13:05 +02:00
|
|
|
},
|
|
|
|
|
TSBufDisable = {
|
|
|
|
|
run = disable_module,
|
|
|
|
|
args = {
|
|
|
|
|
"-nargs=1",
|
2020-09-05 10:20:31 -05:00
|
|
|
"-complete=custom,nvim_treesitter#available_modules",
|
2020-09-04 12:44:19 -05:00
|
|
|
},
|
2020-04-22 11:13:05 +02:00
|
|
|
},
|
|
|
|
|
TSEnableAll = {
|
|
|
|
|
run = enable_all,
|
|
|
|
|
args = {
|
|
|
|
|
"-nargs=+",
|
2020-09-05 10:20:31 -05:00
|
|
|
"-complete=custom,nvim_treesitter#available_modules",
|
2020-09-04 12:44:19 -05:00
|
|
|
},
|
2020-04-22 11:13:05 +02:00
|
|
|
},
|
|
|
|
|
TSDisableAll = {
|
|
|
|
|
run = disable_all,
|
|
|
|
|
args = {
|
|
|
|
|
"-nargs=+",
|
2020-09-05 10:20:31 -05:00
|
|
|
"-complete=custom,nvim_treesitter#available_modules",
|
2020-09-04 12:44:19 -05:00
|
|
|
},
|
2020-04-22 11:13:05 +02:00
|
|
|
},
|
2020-09-23 20:19:03 +02:00
|
|
|
TSConfigInfo = {
|
|
|
|
|
run = config_info,
|
|
|
|
|
args = {
|
|
|
|
|
"-nargs=0",
|
|
|
|
|
},
|
|
|
|
|
},
|
2020-04-22 11:13:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-- @param mod: module (string)
|
|
|
|
|
-- @param ft: filetype (string)
|
2020-06-20 12:21:42 +02:00
|
|
|
function M.is_enabled(mod, lang)
|
|
|
|
|
if not parsers.list[lang] or not parsers.has_parser(lang) then
|
2020-04-25 16:11:53 +02:00
|
|
|
return false
|
|
|
|
|
end
|
2020-04-22 11:13:05 +02:00
|
|
|
|
2020-06-25 13:26:31 -05:00
|
|
|
local module_config = M.get_module(mod)
|
2020-04-22 11:13:05 +02:00
|
|
|
if not module_config then return false end
|
|
|
|
|
|
2020-06-20 12:21:42 +02:00
|
|
|
if not module_config.enable or not module_config.is_supported(lang) then
|
2020-04-22 11:13:05 +02:00
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for _, parser in pairs(module_config.disable) do
|
2020-06-22 11:56:55 +02:00
|
|
|
if lang == parser then return false end
|
2020-04-22 11:13:05 +02:00
|
|
|
end
|
2020-05-08 11:22:59 +02:00
|
|
|
|
2020-04-22 11:13:05 +02:00
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
2020-07-02 10:26:53 -05:00
|
|
|
-- Setup call for users to override module configurations.
|
|
|
|
|
-- @param user_data module overrides
|
2020-04-22 11:13:05 +02:00
|
|
|
function M.setup(user_data)
|
Fix(modules): simplify configs.setup
This prevents a really weird bug were the following function call (after
loading the activated modules) could activate `highlight_current_scope`
```lua
require "nvim-treesitter.configs".setup(
{
highlight = {
enable = false, -- false will disable the whole extension
disable = {"html", "lua"} -- list of language that will be disabled
},
refactor = {
highlight_current_scope = {
enable = false,
inverse_highlighting = true,
disable = {"python", "markdown"}
},
highlight_definitions = {
enable = true,
disable = {"markdown"}
},
},
ensure_installed = "all",
disable = {"markdown"}, -- list of language that will be disabled
}
)
```
2020-08-31 19:04:14 +02:00
|
|
|
config.modules = vim.tbl_deep_extend('force', config.modules, user_data)
|
|
|
|
|
|
2020-09-07 20:29:30 -05:00
|
|
|
local ensure_installed = user_data.ensure_installed or {}
|
|
|
|
|
if #ensure_installed > 0 then
|
|
|
|
|
require'nvim-treesitter.install'.ensure_installed(ensure_installed)
|
|
|
|
|
end
|
|
|
|
|
|
Fix(modules): simplify configs.setup
This prevents a really weird bug were the following function call (after
loading the activated modules) could activate `highlight_current_scope`
```lua
require "nvim-treesitter.configs".setup(
{
highlight = {
enable = false, -- false will disable the whole extension
disable = {"html", "lua"} -- list of language that will be disabled
},
refactor = {
highlight_current_scope = {
enable = false,
inverse_highlighting = true,
disable = {"python", "markdown"}
},
highlight_definitions = {
enable = true,
disable = {"markdown"}
},
},
ensure_installed = "all",
disable = {"markdown"}, -- list of language that will be disabled
}
)
```
2020-08-31 19:04:14 +02:00
|
|
|
config.modules.ensure_installed = nil
|
|
|
|
|
|
|
|
|
|
recurse_modules(function(_, _, new_path)
|
|
|
|
|
local data = utils.get_at_path(config.modules, new_path)
|
|
|
|
|
if data.enable then
|
2020-09-09 23:20:09 -05:00
|
|
|
enable_all(new_path)
|
2020-06-25 13:26:31 -05:00
|
|
|
end
|
Fix(modules): simplify configs.setup
This prevents a really weird bug were the following function call (after
loading the activated modules) could activate `highlight_current_scope`
```lua
require "nvim-treesitter.configs".setup(
{
highlight = {
enable = false, -- false will disable the whole extension
disable = {"html", "lua"} -- list of language that will be disabled
},
refactor = {
highlight_current_scope = {
enable = false,
inverse_highlighting = true,
disable = {"python", "markdown"}
},
highlight_definitions = {
enable = true,
disable = {"markdown"}
},
},
ensure_installed = "all",
disable = {"markdown"}, -- list of language that will be disabled
}
)
```
2020-08-31 19:04:14 +02:00
|
|
|
end, config.modules)
|
2020-06-25 13:26:31 -05:00
|
|
|
end
|
|
|
|
|
|
2020-07-02 10:26:53 -05:00
|
|
|
-- Defines a table of modules that can be attached/detached to buffers
|
|
|
|
|
-- based on language support. A module consist of the following properties:
|
|
|
|
|
-- * @enable Whether the modules is enabled. Can be true or false.
|
|
|
|
|
-- * @disable A list of languages to disable the module for. Only relevant if enable is true.
|
|
|
|
|
-- * @keymaps A list of user mappings for a given module if relevant.
|
|
|
|
|
-- * @is_supported A function which, given a ft, will return true if the ft works on the module.
|
|
|
|
|
-- * @module_path A string path to a module file using `require`. The exported module must contain
|
|
|
|
|
-- an `attach` and `detach` function. This path is not required if `attach` and `detach`
|
|
|
|
|
-- functions are provided directly on the module definition.
|
|
|
|
|
-- * @attach An attach function that is called for each buffer that the module is enabled for. This is required
|
|
|
|
|
-- if a `module_path` is not specified.
|
|
|
|
|
-- * @detach A detach function that is called for each buffer that the module is enabled for. This is required
|
|
|
|
|
-- if a `module_path` is not specified.
|
|
|
|
|
-- Modules are not setup until `init` is invoked by the plugin. This allows modules to be defined in any order
|
|
|
|
|
-- and can be loaded lazily.
|
|
|
|
|
-- @example
|
|
|
|
|
-- require"nvim-treesitter".define_modules {
|
|
|
|
|
-- my_cool_module = {
|
|
|
|
|
-- attach = function()
|
|
|
|
|
-- do_some_cool_setup()
|
|
|
|
|
-- end,
|
|
|
|
|
-- detach = function()
|
|
|
|
|
-- do_some_cool_teardown()
|
|
|
|
|
-- end
|
|
|
|
|
-- }
|
|
|
|
|
-- }
|
|
|
|
|
function M.define_modules(mod_defs)
|
|
|
|
|
if not is_initialized then
|
|
|
|
|
table.insert(queued_modules_defs, mod_defs)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
recurse_modules(function(key, mod, _, group)
|
|
|
|
|
group[key] = vim.tbl_extend("keep", mod, {
|
|
|
|
|
enable = false,
|
|
|
|
|
disable = {},
|
|
|
|
|
is_supported = function() return true end
|
|
|
|
|
})
|
|
|
|
|
end, mod_defs)
|
|
|
|
|
|
2020-07-15 08:45:08 +02:00
|
|
|
config.modules = vim.tbl_deep_extend("keep", config.modules, mod_defs)
|
2020-07-02 10:26:53 -05:00
|
|
|
|
2020-09-09 23:20:09 -05:00
|
|
|
for _, mod in ipairs(M.available_modules(mod_defs)) do
|
|
|
|
|
local module_config = M.get_module(mod)
|
|
|
|
|
if module_config and module_config.enable then
|
|
|
|
|
enable_mod_conf_autocmd(mod)
|
2020-07-02 10:26:53 -05:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Attaches a module to a buffer
|
|
|
|
|
-- @param mod_name the module name
|
|
|
|
|
-- @param bufnr the bufnr
|
|
|
|
|
-- @param lang the language of the buffer
|
|
|
|
|
function M.attach_module(mod_name, bufnr, lang)
|
2020-08-21 07:49:06 -05:00
|
|
|
local bufnr = bufnr or api.nvim_get_current_buf()
|
2020-09-09 23:20:09 -05:00
|
|
|
local lang = lang or parsers.get_buf_lang(bufnr)
|
|
|
|
|
local resolved_mod = resolve_module(mod_name)
|
2020-07-02 10:26:53 -05:00
|
|
|
|
2020-08-21 07:49:06 -05:00
|
|
|
if resolved_mod
|
2020-09-09 23:20:09 -05:00
|
|
|
and not attached_buffers_by_module.has(mod_name, bufnr)
|
|
|
|
|
and M.is_enabled(mod_name, lang) then
|
2020-08-21 07:49:06 -05:00
|
|
|
attached_buffers_by_module.set(mod_name, bufnr, true)
|
2020-07-02 10:26:53 -05:00
|
|
|
resolved_mod.attach(bufnr, lang)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Detaches a module to a buffer
|
|
|
|
|
-- @param mod_name the module name
|
|
|
|
|
-- @param bufnr the bufnr
|
|
|
|
|
function M.detach_module(mod_name, bufnr)
|
|
|
|
|
local resolved_mod = resolve_module(mod_name)
|
2020-08-21 07:49:06 -05:00
|
|
|
local bufnr = bufnr or api.nvim_get_current_buf()
|
2020-07-02 10:26:53 -05:00
|
|
|
|
2020-09-09 23:20:09 -05:00
|
|
|
if resolved_mod and attached_buffers_by_module.has(mod_name, bufnr) then
|
2020-08-21 07:49:06 -05:00
|
|
|
attached_buffers_by_module.remove(mod_name, bufnr)
|
2020-07-02 10:26:53 -05:00
|
|
|
resolved_mod.detach(bufnr)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Gets available modules
|
|
|
|
|
-- @param root root table to find modules
|
|
|
|
|
function M.available_modules(root)
|
2020-06-25 13:26:31 -05:00
|
|
|
local modules = {}
|
|
|
|
|
|
|
|
|
|
recurse_modules(function(_, _, path)
|
|
|
|
|
table.insert(modules, path)
|
2020-07-02 10:26:53 -05:00
|
|
|
end, root)
|
2020-06-25 13:26:31 -05:00
|
|
|
|
|
|
|
|
return modules
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Gets a module config by path
|
|
|
|
|
-- @param mod_path path to the module
|
|
|
|
|
-- @returns the module or nil
|
|
|
|
|
function M.get_module(mod_path)
|
|
|
|
|
local mod = utils.get_at_path(config.modules, mod_path)
|
|
|
|
|
|
|
|
|
|
return M.is_module(mod) and mod or nil
|
2020-04-22 11:13:05 +02:00
|
|
|
end
|
|
|
|
|
|
2020-06-25 13:26:31 -05:00
|
|
|
-- Determines whether the provided table is a module.
|
2020-07-02 10:26:53 -05:00
|
|
|
-- A module should contain an attach and detach function.
|
2020-06-25 13:26:31 -05:00
|
|
|
-- @param mod the module table
|
|
|
|
|
function M.is_module(mod)
|
2020-07-02 10:26:53 -05:00
|
|
|
return type(mod) == 'table'
|
|
|
|
|
and ((type(mod.attach) == 'function' and type(mod.detach) == 'function')
|
|
|
|
|
or type(mod.module_path) == 'string')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Initializes built-in modules and any queued modules
|
|
|
|
|
-- registered by plugins or the user.
|
|
|
|
|
function M.init()
|
|
|
|
|
is_initialized = true
|
|
|
|
|
M.define_modules(builtin_modules)
|
|
|
|
|
|
|
|
|
|
for _, mod_def in ipairs(queued_modules_defs) do
|
|
|
|
|
M.define_modules(mod_def)
|
|
|
|
|
end
|
2020-05-02 11:33:32 +02:00
|
|
|
end
|
|
|
|
|
|
2020-08-26 21:05:27 +02:00
|
|
|
function M.get_update_strategy()
|
|
|
|
|
return config.update_strategy
|
|
|
|
|
end
|
|
|
|
|
|
2020-04-21 23:40:23 +02:00
|
|
|
return M
|