forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.lua
More file actions
123 lines (111 loc) · 2.87 KB
/
config.lua
File metadata and controls
123 lines (111 loc) · 2.87 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
local logger = require("copilot.logger")
---@class copilot_config
local default_config = {
---@class copilot_config_panel
panel = {
enabled = true,
auto_refresh = false,
---@type table<'jump_prev'|'jump_next'|'accept'|'refresh'|'open', false|string>
keymap = {
jump_prev = "[[",
jump_next = "]]",
accept = "<CR>",
refresh = "gr",
open = "<M-CR>",
},
layout = {
position = "bottom",
ratio = 0.4,
},
},
---@class copilot_config_suggestion
suggestion = {
enabled = true,
auto_trigger = false,
hide_during_completion = true,
debounce = 15,
---@type table<'accept'|'accept_word'|'accept_line'|'next'|'prev'|'dismiss', false|string>
keymap = {
accept = "<M-l>",
accept_word = false,
accept_line = false,
next = "<M-]>",
prev = "<M-[>",
dismiss = "<C-]>",
},
},
---@class copilot_config_logging
logger = {
file = vim.fn.stdpath("log") .. "/copilot-lua.log",
file_log_level = vim.log.levels.OFF,
print_log_level = vim.log.levels.WARN,
---@type string<'off'|'messages'|'verbose'>
trace_lsp = "off",
trace_lsp_progress = false,
log_lsp_messages = false,
},
---@type table<string, boolean>
filetypes = {},
---@type string|nil
auth_provider_url = nil,
---@type string[]
workspace_folders = {},
server_opts_overrides = {},
---@type string|nil
copilot_model = nil,
---@type function|string
root_dir = function()
return vim.fs.dirname(vim.fs.find(".git", { upward = true })[1])
end,
---@alias copilot_should_attach fun(bufnr: integer, bufname: string): boolean
---@type copilot_should_attach
should_attach = function(_, _)
if not vim.bo.buflisted then
logger.debug("not attaching, bugger is not 'buflisted'")
return false
end
if vim.bo.buftype ~= "" then
logger.debug("not attaching, buffer 'buftype' is " .. vim.bo.buftype)
return false
end
return true
end,
copilot_node_command = "node",
---@class copilot_config_server
server = {
---@type string<'nodejs', 'binary'>
type = "nodejs",
---@type string|nil
custom_server_filepath = nil,
},
}
local mod = {
---@type copilot_config
config = nil,
}
function mod.setup(opts)
if mod.config then
logger.warn("config is already set")
return mod.config
end
mod.config = vim.tbl_deep_extend("force", default_config, opts or {})
return mod.config
end
function mod.get_root_dir()
if not mod.config then
error("[Copilot] not initialized")
end
local config_root_dir = mod.config.root_dir
local root_dir --[[@as string]]
if type(config_root_dir) == "function" then
root_dir = config_root_dir()
else
root_dir = config_root_dir
end
if not root_dir or root_dir == "" then
root_dir = "."
end
root_dir = vim.fn.fnamemodify(root_dir, ":p:h")
return root_dir
end
return mod