File: init.lua

package info (click to toggle)
neovim-which-key 3.17.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 500 kB
  • sloc: sh: 21; makefile: 2
file content (48 lines) | stat: -rw-r--r-- 1,105 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
local Config = require("which-key.config")
local Util = require("which-key.util")

local M = {}

---@type table<string, wk.Plugin>
M.plugins = {}

function M.setup()
  for name, opts in pairs(Config.plugins) do
    -- only setup plugin if we didnt load it before
    if not M.plugins[name] then
      if type(opts) == "boolean" then
        opts = { enabled = opts }
      end
      opts.enabled = opts.enabled ~= false
      if opts.enabled then
        M.plugins[name] = require("which-key.plugins." .. name)
        M._setup(M.plugins[name], opts)
      end
    end
  end
end

---@param plugin wk.Plugin
function M._setup(plugin, opts)
  if plugin.mappings then
    Config.add(plugin.mappings)
  end

  if plugin.setup then
    plugin.setup(opts)
  end
end

---@param name string
function M.cols(name)
  local plugin = M.plugins[name]
  assert(plugin, "plugin not found")
  local ret = {} ---@type wk.Col[]
  vim.list_extend(ret, plugin.cols or {})
  ret[#ret + 1] = { key = "value", hl = "WhichKeyValue", width = 0.5 }
  return ret
end

---@class wk.Node.plugin.item: wk.Node,wk.Plugin.item

return M