forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopilot.txt
More file actions
631 lines (485 loc) · 19.1 KB
/
copilot.txt
File metadata and controls
631 lines (485 loc) · 19.1 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
*copilot.txt*Fully featured & enhanced replacement for copilot.vim complete with API for interacting with Github Copilot
==============================================================================
1. copilot.lua *copilot-copilot.lua*
This plugin is the pure lua replacement for github/copilot.vim
<https://github.com/github/copilot.vim>. A huge thank you to @tris203 for the
code behind the nes functionality (copilot-lsp
<https://github.com/copilotlsp-nvim/copilot-lsp>).
Motivation behind `copilot.lua` ~
While using `copilot.vim`, for the first time since I started using neovim my
laptop began to overheat. Additionally, I found the large chunks of ghost text
moving around my code, and interfering with my existing cmp ghost text
disturbing. As lua is far more efficient and makes things easier to integrate
with modern plugins, this repository was created.
TABLE OF CONTENTS *copilot-copilot.lua-table-of-contents*
- |copilot-requirements|
- |copilot-install|
- |copilot-authentication|
- |copilot-authentication-with-alternate-github-instances|
- |copilot-setup-and-configuration|
- |copilot-panel|
- |copilot-suggestion|
- |copilot-highlight-groups|
- |copilot-filetypes|
- |copilot-logger|
- |copilot-copilot_node_command|
- |copilot-server_opts_overrides|
- |copilot-workspace_folders|
- |copilot-root_dir|
- |copilot-should_attach|
- |copilot-server|
- |copilot-commands|
- |copilot-integrations|
- |copilot-faq|
REQUIREMENTS *copilot-copilot.lua-requirements*
- Curl
- NeoVim 0.11.0 or higher
- NodeJS v22 or higher if using the default nodejs LSP version
INSTALL *copilot-copilot.lua-install*
Install the plugin with your preferred plugin manager. For example, with
packer.nvim <https://github.com/wbthomason/packer.nvim>:
>lua
use { "zbirenbaum/copilot.lua"
requires = {
"copilotlsp-nvim/copilot-lsp", -- (optional) for NES functionality
},
}
<
AUTHENTICATION ~
You can authenticate using one of the following methods:
Permanent sign-in (Recommended) ~
Once copilot is running, run `:Copilot auth` to start the authentication
process.
Token (not officially supported) ~
Tokens given by `gh auth token` do not support Copilot, you therefore need to
first generate a token through the LSP by:
- Authenticating using the `Permanent sign-in` method
- Grab the token by running `:Copilot auth info`
- You can then safely delete the `github-copilot` folder created in your NeoVim base data directory.
Set either the environment variable `GITHUB_COPILOT_TOKEN` or
`GH_COPILOT_TOKEN` to that token. Note that if you have the variable set, even
empty, the LSP will attempt to use it to log in.
Sign out / Switch accounts ~
To sign out of your current GitHub account:
>
:Copilot auth signout
<
To sign in with a different account:
>
:Copilot auth signin
<
To view your current authentication token information:
>
:Copilot auth info
<
Credentials are stored in: - **Linux/macOS:**
`~/.config/github-copilot/apps.json` (or
`$XDG_CONFIG_HOME/github-copilot/apps.json`) - **Windows:**
`~/AppData/Local/github-copilot/apps.json`
AUTHENTICATION WITH ALTERNATE GITHUB INSTANCES
If your access to Copilot is not provided by the public GitHub instance, you
can set your authentication provider to a custom URL with the corresponding
config key e.g. `auth_provider_url = "https://mycorp.ghe.com/"`.
SETUP AND CONFIGURATION *copilot-copilot.lua-setup-and-configuration*
You have to run the `require("copilot").setup(options)` function in order to
start Copilot. If no options are provided, the defaults are used.
Because the copilot server takes some time to start up, it is recommended that
you lazy load copilot. For example:
>lua
use {
"zbirenbaum/copilot.lua",
requires = {
"copilotlsp-nvim/copilot-lsp", -- (optional) for NES functionality
},
cmd = "Copilot",
event = "InsertEnter",
config = function()
require("copilot").setup({})
end,
}
<
Default configuration ~
>lua
require('copilot').setup({
panel = {
enabled = true,
auto_refresh = false,
keymap = {
jump_prev = "[[",
jump_next = "]]",
accept = "<CR>",
refresh = "gr",
open = "<M-CR>"
},
layout = {
position = "bottom", -- | top | left | right | bottom |
ratio = 0.4
},
},
suggestion = {
enabled = true,
auto_trigger = false,
hide_during_completion = true,
debounce = 15,
trigger_on_accept = true,
keymap = {
accept = "<M-l>",
accept_word = false,
accept_line = false,
next = "<M-]>",
prev = "<M-[>",
dismiss = "<C-]>",
toggle_auto_trigger = false,
},
},
nes = {
enabled = false, -- requires copilot-lsp as a dependency
auto_trigger = false,
keymap = {
accept_and_goto = false,
accept = false,
dismiss = false,
},
},
auth_provider_url = nil, -- URL to authentication provider, if not "https://github.com/"
logger = {
file = vim.fn.stdpath("log") .. "/copilot-lua.log",
file_log_level = vim.log.levels.OFF,
print_log_level = vim.log.levels.WARN,
trace_lsp = "off", -- "off" | "debug" | "verbose"
trace_lsp_progress = false,
log_lsp_messages = false,
},
copilot_node_command = 'node', -- Node.js version must be > 22
workspace_folders = {},
copilot_model = "",
disable_limit_reached_message = false, -- Set to `true` to suppress completion limit reached popup
root_dir = function()
return vim.fs.dirname(vim.fs.find(".git", { upward = true })[1])
end,
should_attach = function(buf_id, _)
if not vim.bo[buf_id].buflisted then
logger.debug("not attaching, buffer is not 'buflisted'")
return false
end
if vim.bo[buf_id].buftype ~= "" then
logger.debug("not attaching, buffer 'buftype' is " .. vim.bo[buf_id].buftype)
return false
end
return true
end,
server = {
type = "nodejs", -- "nodejs" | "binary"
custom_server_filepath = nil,
},
server_opts_overrides = {},
})
<
PANEL ~
Panel can be used to preview suggestions in a split window. You can run the
`:Copilot panel` command to open it.
If `auto_refresh` is `true`, the suggestions are refreshed as you type in the
buffer.
The `copilot.panel` module exposes the following functions:
>lua
require("copilot.panel").accept()
require("copilot.panel").jump_next()
require("copilot.panel").jump_prev()
require("copilot.panel").open({position, ratio})
require("copilot.panel").close()
require("copilot.panel").toggle()
require("copilot.panel").refresh()
require("copilot.panel").is_open()
<
These can also be accessed through the `:Copilot panel <function>` command (eg.
`:Copilot panel accept`).
SUGGESTION ~
When `auto_trigger` is `true`, copilot starts suggesting as soon as you enter
insert mode. When `auto_trigger` is `false`, use the `next`, `prev` or `accept`
keymap to trigger copilot suggestion. When `trigger_on_accept` is `false`, the
keypress will be passed to the buffer as-is, instead of triggering completion.
To toggle auto trigger for the current buffer, use
`require("copilot.suggestion").toggle_auto_trigger()`.
Copilot suggestion is automatically hidden when `popupmenu-completion` is open.
In case you use a custom menu for completion, you can set the
`copilot_suggestion_hidden` buffer variable to `true` to have the same
behavior.
Example using nvim-cmp ~
>lua
cmp.event:on("menu_opened", function()
vim.b.copilot_suggestion_hidden = true
end)
cmp.event:on("menu_closed", function()
vim.b.copilot_suggestion_hidden = false
end)
<
Example using blink.cmp ~
>lua
vim.api.nvim_create_autocmd("User", {
pattern = "BlinkCmpMenuOpen",
callback = function()
vim.b.copilot_suggestion_hidden = true
end,
})
vim.api.nvim_create_autocmd("User", {
pattern = "BlinkCmpMenuClose",
callback = function()
vim.b.copilot_suggestion_hidden = false
end,
})
<
The `copilot.suggestion` module exposes the following functions:
>lua
require("copilot.suggestion").is_visible()
require("copilot.suggestion").accept(modifier)
require("copilot.suggestion").accept_word()
require("copilot.suggestion").accept_line()
require("copilot.suggestion").next()
require("copilot.suggestion").prev()
require("copilot.suggestion").clear_preview()
require("copilot.suggestion").update_preview()
require("copilot.suggestion").dismiss()
require("copilot.suggestion").toggle_auto_trigger()
<
These can also be accessed through the `:Copilot suggestion <function>` command
(eg. `:Copilot suggestion accept`).
HIGHLIGHT GROUPS ~
Copilot uses two highlight groups to style its suggestions:
-----------------------------------------------------------------------
Highlight Group Used For Default Link
----------------------- ----------------------- -----------------------
CopilotSuggestion Inline ghost text Comment
suggestions
CopilotAnnotation Annotations in the Comment
panel and inline
suggestions
-----------------------------------------------------------------------
If these highlight groups are not defined by your colorscheme, they will
default to linking to `Comment`. To customize them, set the highlights
**after** your colorscheme loads, or use a `ColorScheme` autocmd:
>lua
vim.api.nvim_create_autocmd("ColorScheme", {
callback = function()
vim.api.nvim_set_hl(0, "CopilotSuggestion", { fg = "#83a598", italic = true })
vim.api.nvim_set_hl(0, "CopilotAnnotation", { fg = "#83a598" })
end,
})
<
NES (NEXT EDIT SUGGESTION) ~
[!WARNING] This feature is still experimental and may not work as expected in
all scenarios, please report any issues you encounter.
When `enabled` is `true`, copilot will provide suggestions based on the next
edit you are likely to make, through copilot-lsp
<https://github.com/copilotlsp-nvim/copilot-lsp>. If there is no suggestion,
the keymaps will pass through the original keymap.
`copilot-lsp` has a few configurations built-in as well, for additional
configurations, please refer to the copilot-lsp documentation
<https://github.com/copilotlsp-nvim/copilot-lsp/blob/main/README.md>. These
configurations should be set in the `init` function of the `copilot-lsp`
dependency.
>lua
use {
"zbirenbaum/copilot.lua",
requires = {
"copilotlsp-nvim/copilot-lsp",
init = function()
vim.g.copilot_nes_debounce = 500
end,
},
cmd = "Copilot",
event = "InsertEnter",
config = function()
require("copilot").setup({
nes = {
enabled = true,
keymap = {
accept_and_goto = "<leader>p",
accept = false,
dismiss = "<Esc>",
},
},
})
end,
}
<
FILETYPES ~
Specify filetypes for attaching copilot.
Example:
>lua
require("copilot").setup {
filetypes = {
markdown = true, -- overrides default
terraform = false, -- disallow specific filetype
sh = function ()
if string.match(vim.fs.basename(vim.api.nvim_buf_get_name(0)), '^%.env.*') then
-- disable for .env files
return false
end
return true
end,
},
}
<
If you add `"*"` as a filetype, the default configuration for `filetypes`
won’t be used anymore. e.g.
>lua
require("copilot").setup {
filetypes = {
javascript = true, -- allow specific filetype
typescript = true, -- allow specific filetype
["*"] = false, -- disable for all other filetypes and ignore default `filetypes`
},
}
<
LOGGER ~
Logs will be written to the `file` for anything of `file_log_level` or higher.
Logs will be printed to NeoVim (using `notify`) for anything of
`print_log_level` or higher. To turn either off, simply set its level to
`vim.log.levels.OFF`. File logging is done asynchronously to minimize
performance impacts, however there is still some overhead.
Log levels used are the ones defined in `vim.log`:
>lua
vim.log = {
levels = {
TRACE = 0,
DEBUG = 1,
INFO = 2,
WARN = 3,
ERROR = 4,
OFF = 5,
},
}
<
`trace_lsp` controls logging of LSP trace messages (`$/logTrace`) can either
be:
- `off`
- `messages` which will output the LSP messages
- `verbose` which adds additional information to the message.
When `trace_lsp_progress` is true, LSP progress messages (`$/progress`) will
also be logged. When `log_lsp_messages` is true, LSP log messages
(`window/logMessage`) events will be logged.
Careful turning on all logging features as the log files may get very large
over time, and are not pruned by the application.
COPILOT_NODE_COMMAND ~
Use this field to provide the path to a specific node version such as one
installed by nvm. Node.js version must be 22 or newer.
Example:
>lua
copilot_node_command = vim.fn.expand("$HOME") .. "/.config/nvm/versions/node/v22.0.0/bin/node", -- Node.js version must be > 22
<
SERVER_OPTS_OVERRIDES ~
Override copilot lsp client settings. See |vim.lsp.start| for the list of
options. Ensure that the `name` field is not overridden as it is used for
efficiency reasons in numerous checks to verify copilot is actually running.
The `settings` field is where you can customize the copilot lsp behavior. See
SettingsOpts.md <./SettingsOpts.md> for the full list of available settings and
their keys.
Example:
>lua
require("copilot").setup {
server_opts_overrides = {
trace = "verbose",
settings = {
advanced = {
listCount = 10, -- #completions for panel
inlineSuggestCount = 3, -- #completions for getCompletions
}
},
}
}
<
[!NOTE] The `settings` values follow a nested table structure matching the keys
in SettingsOpts.md <./SettingsOpts.md>. For example, `InlineSuggestCount:
["advanced", "inlineSuggestCount"]` becomes `settings = { advanced = {
inlineSuggestCount = 3 } }`.
WORKSPACE_FOLDERS ~
Workspace folders improve Copilot’s suggestions. By default, the root_dir is
used as a workspace_folder.
Additional folders can be added through the configuration as such:
>lua
workspace_folders = {
"/home/user/gits",
"/home/user/projects",
}
<
They can also be added runtime, using the command `:Copilot workspace add
[folderpath]` where `[folderpath]` is the workspace folder.
ROOT_DIR ~
This allows changing the function that gets the root folder, the default looks
for a parent folder that contains the folder `.git`. If none is found, it will
use the current working directory.
SHOULD_ATTACH ~
This function is called to determine if copilot should attach to the buffer or
not. It is useful if you would like to go beyond the filetypes and have more
control over when copilot should attach. You can also use it to attach to
buflisted buffers by simply omitting that portion from the function. Since this
happens before attaching to the buffer, it is good to prevent Copilot from
reading sensitive files.
An example of this would be:
>lua
require("copilot").setup {
should_attach = function(_, bufname)
if string.match(bufname, "env") then
return false
end
return true
end
}
<
SERVER ~
[!CAUTION] `"binary"` mode is still very much experimental, please report any
issues you encounter.
`type` can be either `"nodejs"` or `"binary"`. The binary version will be
downloaded if used.
`custom_server_filepath` is used to specify the server path (filename included)
of either the `js` file if using `"nodejs"` or to the binary if using
`"binary"`. The filename on its own can also be set if accessible through your
PATH. When using `"binary"`, the download process will be disabled and the
binary will be used directly. example:
>lua
require("copilot").setup {
server = {
type = "nodejs",
custom_server_filepath = "/home/user/copilot-lsp/language-server.js",
},
}
<
COMMANDS *copilot-copilot.lua-commands*
`copilot.lua` defines the `:Copilot` command that can perform various actions.
It has completion support, so try it out.
INTEGRATIONS *copilot-copilot.lua-integrations*
The `copilot.api` module can be used to build integrations on top of
`copilot.lua`.
- zbirenbaum/copilot-cmp <https://github.com/zbirenbaum/copilot-cmp>: Integration with `nvim-cmp` <https://github.com/hrsh7th/nvim-cmp>.
- giuxtaposition/blink-cmp-copilot <https://github.com/giuxtaposition/blink-cmp-copilot>: Integration with `blink.cmp` <https://github.com/Saghen/blink.cmp>.
- fang2hou/blink-copilot <https://github.com/fang2hou/blink-copilot>: Integration with `blink.cmp` <https://github.com/Saghen/blink.cmp>, with some differences.
- AndreM222/copilot-lualine <https://github.com/AndreM222/copilot-lualine>: Integration with `lualine.nvim` <https://github.com/nvim-lualine/lualine.nvim>.
FAQ *copilot-copilot.lua-faq*
Certificate Parsing Error
This is an issue with the copilot lsp itself as described in this discussion
<https://github.com/orgs/community/discussions/136273#discussioncomment-10433527>.
Please update the plugin to the latest version to solve this issue. If updating
does not help, some users have reported that updating the
`/usr/bin/update-ca-trust` and removing the –comment option from the trust
extract commands solves the issue. However this has not been verified by the
author of this plugin and may have unintended consequences so thread with care.
Multiple offset encodings warning
As discussed in #247, the problem arises because two or more clients are using
different offset encodings. To solve this, in lspconfig:
>lua
local capabilities = vim.lsp.protocol.make_client_capabilities() -- Get The capabilities
capabilities.general.positionEncodings = { "utf-16" } -- Set the offset encoding, see `:h vim.lsp.start` for more info
require("lspconfig")[server].setup({ capabilities = capabilities }) -- Setup the server
<
Set the same for copilot in `server_opts_overrides`:
>lua
server_opts_overrides = {
offset_encoding = "utf-16" -- Set the offset encoding same as above, see `:h vim.lsp.start` for more info
}
<
Refer to your plugins documentation for changes.
==============================================================================
2. Links *copilot-links*
1. *@tris203*:
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
vim:tw=78:ts=8:noet:ft=help:norl: