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
84 lines (74 loc) · 2.24 KB
/
init.lua
File metadata and controls
84 lines (74 loc) · 2.24 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
local M = { client_info = nil }
local client = require("copilot.client")
local highlight = require("copilot.highlight")
local panel = require("copilot.panel")
local suggestion = require("copilot.suggestion")
local defaults = {
panel = {
enabled = true,
auto_refresh = false,
keymap = {
jump_prev = "[[",
jump_next = "]]",
accept = "<CR>",
refresh = "gr",
open = "<M-CR>"
}
},
suggestion = {
enabled = true,
auto_trigger = false,
debounce = 75,
keymap = {
accept = "<M-l>",
next = "<M-]>",
prev = "<M-[>",
dismiss = "<C-]>",
}
},
ft_disable = nil,
filetypes = {},
copilot_node_command = "node",
plugin_manager_path = vim.fn.stdpath("data") .. "/site/pack/packer",
server_opts_overrides = {},
}
local create_cmds = function (_)
vim.api.nvim_create_user_command("CopilotDetach", function()
local client_instance = require("copilot.util").get_copilot_client()
local valid = client_instance and vim.lsp.buf_is_attached(0, client_instance.id)
if not valid then return end
vim.lsp.buf_detach_client(0, client_instance.id)
end, {})
vim.api.nvim_create_user_command("CopilotStop", function()
local client_instance = require("copilot.util").get_copilot_client()
if not client_instance then return end
vim.lsp.stop_client(client_instance.id)
end, {})
vim.api.nvim_create_user_command("CopilotPanel", function ()
vim.deprecate("':CopilotPanel'", "':Copilot panel'", "in future", "copilot.lua")
vim.cmd("Copilot panel")
end, {})
vim.api.nvim_create_user_command("CopilotAuth", function()
vim.deprecate("':CopilotAuth'", "':Copilot auth'", "in future", "copilot.lua")
vim.cmd("Copilot auth")
end, {})
end
local config_handler = function(opts)
local user_config = opts and vim.tbl_deep_extend("force", defaults, opts) or defaults
return user_config
end
M.setup = function(opts)
local user_config = config_handler(opts)
vim.schedule(function ()
client.start(user_config)
if user_config.panel.enabled then
panel.setup(user_config.panel)
create_cmds(user_config)
end
if user_config.suggestion.enabled then
suggestion.setup(user_config.suggestion)
end
end)
highlight.setup()
end
return M