forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
77 lines (66 loc) · 3.02 KB
/
init.lua
File metadata and controls
77 lines (66 loc) · 3.02 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
local logger = require("copilot.logger")
---@class CopilotConfig
---@field panel PanelConfig
---@field suggestion SuggestionConfig
---@field logger LoggerConfig
---@field server ServerConfig
---@field filetypes table<string, boolean> Filetypes to enable Copilot for
---@field auth_provider_url string|nil URL for the authentication provider
---@field workspace_folders string[] Workspace folders to enable Copilot for
---@field server_opts_overrides? table<string, any> Options to override for the server
---@field copilot_model string|nil Model to use for Copilot, LSP server dictates the default
---@field root_dir RootDirFuncOrString Root directory for the project, defaults to the nearest .git directory
---@field should_attach ShouldAttachFunc Function to determine if Copilot should attach to the buffer
---@field copilot_node_command string Path to the Node.js executable, defaults to "node"
local initialized = false
---@class CopilotConfig
local M = {
panel = require("copilot.config.panel").default,
suggestion = require("copilot.config.suggestion").default,
logger = require("copilot.config.logger").default,
server = require("copilot.config.server").default,
root_dir = require("copilot.config.root_dir").default,
should_attach = require("copilot.config.should_attach").default,
filetypes = {},
auth_provider_url = nil,
workspace_folders = {},
server_opts_overrides = {},
copilot_model = nil,
copilot_node_command = "node",
}
---@param user_configs CopilotConfig
function M.merge_with_user_configs(user_configs)
logger.trace("setting up configuration, opts", user_configs)
if initialized then
logger.warn("config is already set")
return
end
local merged = vim.tbl_deep_extend("force", M, user_configs or {})
for k, v in pairs(merged) do
M[k] = v
end
M.validate(M)
initialized = true
end
---@param config CopilotConfig
function M.validate(config)
vim.validate("panel", config.panel, "table")
vim.validate("suggestion", config.suggestion, "table")
vim.validate("logger", config.logger, "table")
vim.validate("server", config.server, "table")
vim.validate("filetypes", config.filetypes, "table")
vim.validate("auth_provider_url", config.auth_provider_url, { "string", "nil" })
vim.validate("workspace_folders", config.workspace_folders, "table")
vim.validate("server_opts_overrides", config.server_opts_overrides, "table", true)
vim.validate("copilot_model", config.copilot_model, { "string", "nil" })
vim.validate("root_dir", config.root_dir, { "string", "function" })
vim.validate("should_attach", config.should_attach, "function")
vim.validate("copilot_node_command", config.copilot_node_command, "string")
require("copilot.config.panel").validate(config.panel)
require("copilot.config.suggestion").validate(config.suggestion)
require("copilot.config.logger").validate(config.logger)
require("copilot.config.server").validate(config.server)
require("copilot.config.root_dir").validate(config.root_dir)
require("copilot.config.should_attach").validate(config.should_attach)
end
return M