forked from Davidyz/VectorCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.lua
More file actions
90 lines (83 loc) · 2.47 KB
/
Copy pathconfig.lua
File metadata and controls
90 lines (83 loc) · 2.47 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---@class VectorCodeConfig
---@field n_query integer?
---@field notify boolean?
---@field timeout_ms number?
---@field exclude_this boolean?
---@field events string|string[]|nil
local config = {
n_query = 1,
notify = true,
timeout_ms = 5000,
exclude_this = true,
events = { "BufWritePost", "InsertEnter", "BufReadPost" },
}
local setup_config = vim.deepcopy(config, true)
local notify_opts = { title = "VectorCode" }
---@param opts {notify:boolean}?
local has_cli = function(opts)
opts = opts or { notify = false }
local ok = vim.fn.executable("vectorcode") == 1
if not ok and opts.notify then
vim.notify("VectorCode CLI is not executable!", vim.log.levels.ERROR, notify_opts)
end
return ok
end
---@generic T: function
---@param func T
---@return T
local check_cli_wrap = function(func)
if not has_cli() then
vim.notify("VectorCode CLI is not executable!", vim.log.levels.ERROR, notify_opts)
end
return func
end
return {
get_default_config = function()
return vim.deepcopy(config, true)
end,
setup = check_cli_wrap(
---@param opts VectorCodeConfig?
function(opts)
setup_config = vim.tbl_deep_extend("force", config, opts or {})
vim.api.nvim_create_user_command("VectorCode", function(args)
if args.fargs[1] == "register" then
local bufnr = vim.api.nvim_get_current_buf()
require("vectorcode.cacher").register_buffer(
bufnr,
{ run_on_register = true }
)
vim.notify(
("Buffer %d has been registered for VectorCode."):format(bufnr),
vim.log.levels.INFO,
notify_opts
)
elseif args.fargs[1] == "deregister" then
local buf_nr = vim.api.nvim_get_current_buf()
require("vectorcode.cacher").deregister_buffer(buf_nr, { notify = true })
else
vim.notify(
([[Command "VectorCode %s" was not recognised.]]):format(args.args),
vim.log.levels.ERROR,
notify_opts
)
end
end, {
nargs = 1,
complete = function(arglead, cmd, cursorpos)
if require("vectorcode.cacher").buf_is_registered(0) then
return { "register", "deregister" }
else
return { "register" }
end
end,
})
end
),
get_user_config = function()
return vim.deepcopy(setup_config, true)
end,
notify_opts = notify_opts,
---@return boolean
has_cli = has_cli,
check_cli_wrap = check_cli_wrap,
}