Skip to content

Commit fc5d6a1

Browse files
committed
feat: add Copilot panel close and is_open commands
fixes #241
1 parent 8cfbb5a commit fc5d6a1

File tree

6 files changed

+148
-2
lines changed

6 files changed

+148
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,12 @@ require("copilot.panel").accept()
200200
require("copilot.panel").jump_next()
201201
require("copilot.panel").jump_prev()
202202
require("copilot.panel").open({position, ratio})
203+
require("copilot.panel").close()
203204
require("copilot.panel").toggle()
204205
require("copilot.panel").refresh()
206+
require("copilot.panel").is_open()
205207
```
208+
These can also be accessed through the `:Copilot panel <function>` command (eg. `:Copilot panel accept`).
206209

207210
### suggestion
208211

@@ -265,6 +268,7 @@ require("copilot.suggestion").prev()
265268
require("copilot.suggestion").dismiss()
266269
require("copilot.suggestion").toggle_auto_trigger()
267270
```
271+
These can also be accessed through the `:Copilot suggestion <function>` command (eg. `:Copilot suggestion accept`).
268272

269273
### filetypes
270274

lua/copilot/panel/init.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,16 @@ function M.toggle()
529529
end
530530
end
531531

532+
function M.close()
533+
if panel.winid and vim.api.nvim_win_is_valid(panel.winid) then
534+
panel:close()
535+
end
536+
end
537+
538+
function M.is_open()
539+
return (panel.winid and vim.api.nvim_win_is_valid(panel.winid)) or false
540+
end
541+
532542
function M.refresh()
533543
vim.api.nvim_buf_call(vim.uri_to_bufnr(utils.panel_uri_to_doc_uri(panel.panel_uri)), function()
534544
panel:refresh()

plugin/copilot.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local completion_store = {
22
[""] = { "auth", "attach", "detach", "disable", "enable", "panel", "status", "suggestion", "toggle", "version" },
33
auth = { "signin", "signout", "info" },
4-
panel = { "accept", "jump_next", "jump_prev", "open", "refresh", "toggle" },
4+
panel = { "accept", "jump_next", "jump_prev", "open", "refresh", "toggle", "close", "is_open" },
55
suggestion = { "accept", "accept_line", "accept_word", "dismiss", "next", "prev", "toggle_auto_trigger" },
66
workspace = { "add" },
77
}
@@ -50,10 +50,14 @@ vim.api.nvim_create_user_command("Copilot", function(opts)
5050
end
5151

5252
require("copilot.client").use_client(function()
53-
mod[action_name]({
53+
local result = mod[action_name]({
5454
force = opts.bang,
5555
args = remaining_args,
5656
})
57+
58+
if result ~= nil then
59+
print(tostring(result))
60+
end
5761
end)
5862
end, {
5963
bang = true,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--|---------|---------|---------|---------|---------|---------|---------|---------|
2+
01|
3+
02|~
4+
03|~
5+
04|~
6+
05|~
7+
06|~
8+
07|~
9+
08|~
10+
09|~
11+
10|~
12+
11|~
13+
12|~
14+
13|~
15+
14|~
16+
15|~
17+
16|~
18+
17|~
19+
18|~
20+
19|~
21+
20|~
22+
21|~
23+
22|~
24+
23|[No Name] 0,0-1 All
25+
24|
26+
27+
--|---------|---------|---------|---------|---------|---------|---------|---------|
28+
01|00000000000000000000000000000000000000000000000000000000000000000000000000000000
29+
02|11111111111111111111111111111111111111111111111111111111111111111111111111111111
30+
03|11111111111111111111111111111111111111111111111111111111111111111111111111111111
31+
04|11111111111111111111111111111111111111111111111111111111111111111111111111111111
32+
05|11111111111111111111111111111111111111111111111111111111111111111111111111111111
33+
06|11111111111111111111111111111111111111111111111111111111111111111111111111111111
34+
07|11111111111111111111111111111111111111111111111111111111111111111111111111111111
35+
08|11111111111111111111111111111111111111111111111111111111111111111111111111111111
36+
09|11111111111111111111111111111111111111111111111111111111111111111111111111111111
37+
10|11111111111111111111111111111111111111111111111111111111111111111111111111111111
38+
11|11111111111111111111111111111111111111111111111111111111111111111111111111111111
39+
12|11111111111111111111111111111111111111111111111111111111111111111111111111111111
40+
13|11111111111111111111111111111111111111111111111111111111111111111111111111111111
41+
14|11111111111111111111111111111111111111111111111111111111111111111111111111111111
42+
15|11111111111111111111111111111111111111111111111111111111111111111111111111111111
43+
16|11111111111111111111111111111111111111111111111111111111111111111111111111111111
44+
17|11111111111111111111111111111111111111111111111111111111111111111111111111111111
45+
18|11111111111111111111111111111111111111111111111111111111111111111111111111111111
46+
19|11111111111111111111111111111111111111111111111111111111111111111111111111111111
47+
20|11111111111111111111111111111111111111111111111111111111111111111111111111111111
48+
21|11111111111111111111111111111111111111111111111111111111111111111111111111111111
49+
22|11111111111111111111111111111111111111111111111111111111111111111111111111111111
50+
23|22222222222222222222222222222222222222222222222222222222222222222222222222222222
51+
24|33333333333333333333333333333333333333333333333333333333333333333333333333333333
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--|---------|---------|---------|---------|---------|---------|---------|---------|
2+
01|
3+
02|~
4+
03|~
5+
04|~
6+
05|~
7+
06|~
8+
07|~
9+
08|~
10+
09|~
11+
10|~
12+
11|~
13+
12|~
14+
13|~
15+
14|[No Name] 0,0-1 All
16+
15|
17+
16|
18+
17|
19+
18|
20+
19|
21+
20|
22+
21|
23+
22|
24+
23|copilot://// [RO] 1,0-1 All
25+
24|
26+
27+
--|---------|---------|---------|---------|---------|---------|---------|---------|
28+
01|00000000000000000000000000000000000000000000000000000000000000000000000000000000
29+
02|11111111111111111111111111111111111111111111111111111111111111111111111111111111
30+
03|11111111111111111111111111111111111111111111111111111111111111111111111111111111
31+
04|11111111111111111111111111111111111111111111111111111111111111111111111111111111
32+
05|11111111111111111111111111111111111111111111111111111111111111111111111111111111
33+
06|11111111111111111111111111111111111111111111111111111111111111111111111111111111
34+
07|11111111111111111111111111111111111111111111111111111111111111111111111111111111
35+
08|11111111111111111111111111111111111111111111111111111111111111111111111111111111
36+
09|11111111111111111111111111111111111111111111111111111111111111111111111111111111
37+
10|11111111111111111111111111111111111111111111111111111111111111111111111111111111
38+
11|11111111111111111111111111111111111111111111111111111111111111111111111111111111
39+
12|11111111111111111111111111111111111111111111111111111111111111111111111111111111
40+
13|11111111111111111111111111111111111111111111111111111111111111111111111111111111
41+
14|22222222222222222222222222222222222222222222222222222222222222222222222222222222
42+
15|00000000000000000000000000000000000000000000000000000000000000000000000000000000
43+
16|00000000000000000000000000000000000000000000000000000000000000000000000000000000
44+
17|11111111111111111111111111111111111111111111111111111111111111111111111111111111
45+
18|11111111111111111111111111111111111111111111111111111111111111111111111111111111
46+
19|11111111111111111111111111111111111111111111111111111111111111111111111111111111
47+
20|11111111111111111111111111111111111111111111111111111111111111111111111111111111
48+
21|11111111111111111111111111111111111111111111111111111111111111111111111111111111
49+
22|11111111111111111111111111111111111111111111111111111111111111111111111111111111
50+
23|33333333333333333333333333333333333333333333333333333333333333333333333333333333
51+
24|44444444444444444444444444444444444444444444444444444444444444444444444444444444

tests/test_command.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,30 @@ T["command()"]["panel toggle - close works"] = function()
3636
reference_screenshot(child.get_screenshot())
3737
end
3838

39+
T["command()"]["panel open - it works"] = function()
40+
child.configure_copilot()
41+
child.cmd("Copilot panel open")
42+
reference_screenshot(child.get_screenshot())
43+
end
44+
45+
T["command()"]["panel close - it works"] = function()
46+
child.configure_copilot()
47+
child.cmd("Copilot panel open")
48+
child.cmd("Copilot panel close")
49+
reference_screenshot(child.get_screenshot())
50+
end
51+
52+
T["command()"]["panel is_open - is opened - returns true"] = function()
53+
child.configure_copilot()
54+
child.cmd("Copilot panel open")
55+
local is_open = child.cmd_capture("Copilot panel is_open")
56+
u.expect_match(is_open, "true")
57+
end
58+
59+
T["command()"]["panel is_open - is closed - returns false"] = function()
60+
child.configure_copilot()
61+
local is_open = child.cmd_capture("Copilot panel is_open")
62+
u.expect_match(is_open, "false")
63+
end
64+
3965
return T

0 commit comments

Comments
 (0)