-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopilot_agent.lua
More file actions
174 lines (145 loc) · 6.09 KB
/
Copy pathcopilot_agent.lua
File metadata and controls
174 lines (145 loc) · 6.09 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
-- Copyright 2026 ray-x. All rights reserved.
-- Use of this source code is governed by an Apache 2.0
-- license that can be found in the LICENSE file.
if vim.g.loaded_copilot_agent_plugin == 1 then
return
end
vim.g.loaded_copilot_agent_plugin = 1
local copilot_agent = require('copilot_agent')
vim.api.nvim_create_user_command('CopilotAgentChat', function(opts)
local args = opts.fargs or {}
local fullscreen = vim.tbl_contains(args, 'fullscreen') or vim.tbl_contains(args, 'fs')
copilot_agent.open_chat({ fullscreen = fullscreen or nil })
end, {
nargs = '?',
desc = 'Open Copilot Go chat (args: fullscreen)',
complete = function()
return { 'fullscreen' }
end,
})
vim.api.nvim_create_user_command('CopilotAgentChatToggle', function()
copilot_agent.toggle_chat()
end, { desc = 'Hide/show Copilot chat UI without restarting the session' })
vim.api.nvim_create_user_command('CopilotAgentChatFocus', function()
copilot_agent.focus_chat()
end, { desc = 'Focus or switch to an open Copilot chat buffer' })
vim.api.nvim_create_user_command('CopilotAgentDashboard', function()
copilot_agent.open_dashboard()
end, { desc = 'Open the Copilot Agent startup dashboard' })
vim.api.nvim_create_user_command('CopilotAgentNewSession', function()
copilot_agent.new_session()
end, { desc = 'Create a new Copilot Go session' })
vim.api.nvim_create_user_command('CopilotAgentSwitchSession', function()
copilot_agent.switch_session()
end, { desc = 'Switch to a different Copilot session' })
vim.api.nvim_create_user_command('CopilotAgentProvider', function(command)
local provider = vim.trim(command.args or '')
copilot_agent.switch_provider(provider ~= '' and provider or nil)
end, {
nargs = '?',
complete = function(arglead)
return copilot_agent.complete_provider(arglead)
end,
desc = 'Switch to a provider and attach to an existing session or create a new one',
})
vim.api.nvim_create_user_command('CopilotAgentDeleteSession', function()
copilot_agent.delete_session()
end, { desc = 'Delete a persisted Copilot session from a picker' })
vim.api.nvim_create_user_command('CopilotAgentStart', function()
copilot_agent.start_service()
end, { desc = 'Start the Copilot Go service with the current config' })
vim.api.nvim_create_user_command('CopilotAgentServerStart', function()
copilot_agent.start_service()
end, { desc = 'Start the Copilot Agent server with the current config' })
vim.api.nvim_create_user_command('CopilotAgentAsk', function(command)
copilot_agent.ask(table.concat(command.fargs, ' '))
end, {
nargs = '*',
desc = 'Send a prompt to Copilot Go',
})
vim.api.nvim_create_user_command('CopilotAgentMode', function(command)
local mode = vim.trim(table.concat(command.fargs, ' '))
if mode == '' then
vim.notify('CopilotAgentMode requires ask, plan, agent, test, or autopilot', vim.log.levels.WARN)
return
end
copilot_agent.set_input_mode(mode)
end, {
nargs = '?',
complete = function()
return { 'ask', 'plan', 'agent', 'test', 'autopilot' }
end,
desc = 'Set the Copilot input mode (ask, plan, agent, test, autopilot)',
})
vim.api.nvim_create_user_command('CopilotAgentCompose', function(command)
local arg = vim.trim(table.concat(command.fargs, ' '))
local opts = {}
if arg ~= '' then
if arg ~= 'tab' then
vim.notify('CopilotAgentCompose only accepts "tab" as an optional argument', vim.log.levels.WARN)
return
end
opts.layout = 'tab'
end
copilot_agent.open_compose(opts)
end, {
nargs = '?',
complete = function()
return { 'tab' }
end,
desc = 'Open the Copilot compose scratch buffer',
})
vim.api.nvim_create_user_command('CopilotAgentPromoteToCompose', function()
copilot_agent.promote_to_compose()
end, { desc = 'Move the prompt buffer text into the Copilot compose buffer' })
vim.api.nvim_create_user_command('CopilotAgentSendBuffer', function()
copilot_agent.send_buffer()
end, { desc = 'Send the active Copilot compose buffer' })
vim.api.nvim_create_user_command('CopilotAgentModel', function(command)
copilot_agent.select_model(table.concat(command.fargs, ' '))
end, {
nargs = '*',
complete = function(arglead)
return copilot_agent.complete_model(arglead)
end,
desc = 'Select or set the Copilot model',
})
vim.api.nvim_create_user_command('CopilotAgentStop', function(command)
copilot_agent.stop(command.bang)
end, {
bang = true,
desc = 'Disconnect the active Copilot Go session',
})
vim.api.nvim_create_user_command('CopilotAgentCancel', function()
copilot_agent.cancel()
end, { desc = 'Cancel the current in-progress Copilot turn (abort mid-stream)' })
vim.api.nvim_create_user_command('CopilotAgentStatus', function()
copilot_agent.status()
end, { desc = 'Show Copilot Go session state' })
vim.api.nvim_create_user_command('CopilotAgentDebugService', function()
copilot_agent.debug_service()
end, { desc = 'Show detailed Copilot Go service discovery/startup debug info' })
vim.api.nvim_create_user_command('CopilotAgentLsp', function()
copilot_agent.start_lsp()
end, { desc = 'Start the Copilot LSP server (code actions: explain, fix, add tests, add docs)' })
vim.api.nvim_create_user_command('CopilotAgentPasteImage', function()
copilot_agent.paste_clipboard_image()
end, { desc = 'Paste image from clipboard and add as attachment to next Copilot message' })
vim.api.nvim_create_user_command('CopilotAgentInstall', function()
copilot_agent.install_binary()
end, { desc = 'Download the pre-built copilot-agent binary for the current platform' })
vim.api.nvim_create_user_command('CopilotAgentRetryInput', function()
copilot_agent.retry_input()
end, { desc = 'Re-show the last dismissed ask_user prompt' })
vim.api.nvim_create_user_command('CopilotAgentDiff', function()
copilot_agent.review_diff()
end, { desc = 'Pick two checkpoints and open vimdiff for a changed file between them' })
vim.api.nvim_create_user_command('CopilotAgentFugitiveCommit', function(command)
copilot_agent.fugitive_commit(vim.trim(table.concat(command.fargs, ' ')))
end, {
nargs = '?',
complete = function()
return { 'last' }
end,
desc = 'Generate a commit message and open fugitive commit, or reuse the last assistant reply with "last"',
})