Skip to content

Commit 2202f7a

Browse files
authored
feat: add copilot.suggestion module (zbirenbaum#53)
1 parent 2e00dba commit 2202f7a

File tree

4 files changed

+562
-0
lines changed

4 files changed

+562
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ The following is the default configuration:
6565
panel = { -- no config options yet
6666
enabled = true,
6767
},
68+
suggestion = {
69+
enabled = true,
70+
auto_trigger = false,
71+
debounce = 75,
72+
keymap = {
73+
accept = "<M-l>",
74+
next = "<M-]>",
75+
prev = "<M-[>",
76+
dismiss = "<C-]>",
77+
},
78+
},
6879
ft_disable = {},
6980
copilot_node_command = 'node', -- Node version must be < 18
7081
plugin_manager_path = vim.fn.stdpath("data") .. "/site/pack/packer",
@@ -84,6 +95,29 @@ require("copilot").setup {
8495

8596
```
8697

98+
#### suggestion
99+
100+
When `auto_trigger` is `true`, copilot starts suggesting as soon as you enter insert mode.
101+
102+
When `auto_trigger` is `false`, use the `next` or `prev` keymap to trigger copilot suggestion.
103+
104+
To toggle auto trigger for the current buffer, use `require("copilot.suggestion").toggle_auto_trigger()`.
105+
106+
Copilot suggestion is automatically hidden when `popupmenu-completion` is open. In case you use a custom
107+
menu for completion, you can set the `copilot_suggestion_hidden` buffer variable to `true` to have the
108+
same behavior. For example, with `nvim-cmp`:
109+
110+
```lua
111+
cmp.event:on("menu_opened", function()
112+
vim.b.copilot_suggestion_hidden = true
113+
end)
114+
115+
cmp.event:on("menu_closed", function()
116+
vim.b.copilot_suggestion_hidden = false
117+
end)
118+
```
119+
120+
87121
##### ft_disable
88122

89123
Prevents copilot from attaching to buffers with specific filetypes.

lua/copilot/highlight.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
local mod = {
2+
group = {
3+
CopilotAnnotation = "CopilotAnnotation",
4+
CopilotSuggestion = "CopilotSuggestion",
5+
},
6+
}
7+
8+
local links = {
9+
[mod.group.CopilotAnnotation] = "Comment",
10+
[mod.group.CopilotSuggestion] = "Comment",
11+
}
12+
13+
function mod.setup()
14+
for from_group, to_group in pairs(links) do
15+
vim.api.nvim_command("highlight default link " .. from_group .. " " .. to_group)
16+
end
17+
end
18+
19+
return mod

lua/copilot/init.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
local M = { client_info = nil }
22
local client = require("copilot.client")
3+
local highlight = require("copilot.highlight")
4+
local suggestion = require("copilot.suggestion")
35
local defaults = {
46
panel = { -- no config options yet
57
enabled = true,
68
},
9+
suggestion = {
10+
enabled = true,
11+
auto_trigger = false,
12+
debounce = 75,
13+
keymap = {
14+
accept = "<M-l>",
15+
next = "<M-]>",
16+
prev = "<M-[>",
17+
dismiss = "<C-]>",
18+
}
19+
},
720
ft_disable = {},
821
copilot_node_command = "node",
922
plugin_manager_path = vim.fn.stdpath("data") .. "/site/pack/packer",
@@ -49,7 +62,12 @@ M.setup = function(opts)
4962
create_cmds(user_config)
5063
end
5164

65+
if user_config.suggestion.enabled then
66+
suggestion.setup(user_config.suggestion)
67+
end
5268
end)
69+
70+
highlight.setup()
5371
end
5472

5573
return M

0 commit comments

Comments
 (0)