plugin_mgmt.lua 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ---@class PluginConfig
  2. ---@field disable boolean Mark a plugin as inactive
  3. ---@field as string Specifies an alias under which to install the plugin
  4. ---@field installer function Specifies custom installer. See "custom installers" below.
  5. ---@field updater function Specifies custom updater. See "custom installers" below.
  6. ---@field after string | table Specifies plugins to load before this plugin. See "sequencing" below
  7. ---@field rtp string Specifies a subdirectory of the plugin to add to runtimepath.
  8. ---@field opt boolean Manually marks a plugin as optional.
  9. ---@field bufread boolean Manually specifying if a plugin needs BufRead after being loaded
  10. ---@field branch string Specifies a git branch to use
  11. ---@field tag string Specifies a git tag to use. Supports '*' for "latest tag"
  12. ---@field commit string Specifies a git commit to use
  13. ---@field lock boolean Skip updating this plugin in updates/syncs. Still cleans.
  14. ---@field run string Post-update/install hook. See "update/install hooks".
  15. ---@field requires string | table Specifies plugin dependencies. See "dependencies".
  16. ---@field rocks string | table Specifies Luarocks dependencies for the plugin
  17. ---@field config string | function Specifies code to run after this plugin is loaded.
  18. ---@field setup string | function Specifies code to run before this plugin is loaded. The code is ran even if the plugin is waiting for other conditions (ft, cond...) to be met. Implies opt = true
  19. ---@field cmd string | table Specifies commands which load this plugin. Can be an autocmd pattern. Imply lazy-loading and imply opt = true.
  20. ---@field ft string | table Specifies filetypes which load this plugin. Imply lazy-loading and imply opt = true.
  21. ---@field keys string | table Specifies maps which load this plugin. See "Keybindings". imply lazy-loading and imply opt = true.
  22. ---@field event string | table Specifies autocommand events which load this plugin. Imply lazy-loading and imply opt = true.
  23. ---@field fn string | table -- Specifies functions which load this plugin. Imply lazy-loading and imply opt = true.
  24. ---@field cond string Specifies a conditional test to load this plugin. Imply lazy-loading and imply opt = true.
  25. ---@field module string | table -- Specifies Lua module names for require. When requiring a string which starts with one of these module names, the plugin will be loaded. Imply lazy-loading and imply opt = true.
  26. ---@field module_pattern string | table -- Specifies Lua pattern of Lua module names for require. When requiring a string which matches one of these patterns, the plugin will be loaded. Imply lazy-loading and imply opt = true.
  27. --- Adds plugin to install and setup
  28. --- @param plugin_config PluginConfig
  29. ncvim.plugin = function(plugin_config)
  30. table.insert(ncvim.plugins, plugin_config)
  31. end
  32. --- Installs plugins and does configuration with packer
  33. ncvim.install_plugins = function()
  34. for _, plugin in ipairs(ncvim.plugins) do
  35. require('packer').use(plugin)
  36. end
  37. end
  38. local transform_for_lazy = function(plugin)
  39. if type(plugin) == 'string' then
  40. return plugin
  41. end
  42. plugin.init = plugin.setup
  43. plugin.dependencies = plugin.dependencies or plugin.requires
  44. plugin.name = plugin.as
  45. plugin.lazy = plugin.opt
  46. plugin.build = plugin.run
  47. plugin.pin = plugin.lock
  48. plugin.enabled = not plugin.disable
  49. plugin.version = plugin.tag
  50. return plugin
  51. end
  52. --- Installs plugins and does configuration with packer
  53. ncvim.install_plugins_lazy = function()
  54. local transformed = {}
  55. for _, plugin in ipairs(ncvim.plugins) do
  56. table.insert(transformed, transform_for_lazy(plugin))
  57. end
  58. require('lazy').setup(transformed)
  59. end