Skip to content

Commit db575ff

Browse files
authored
docs: update README (zbirenbaum#60)
1 parent e1fb24a commit db575ff

1 file changed

Lines changed: 111 additions & 65 deletions

File tree

README.md

Lines changed: 111 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,137 @@
11
# copilot.lua
22

3-
This plugin is the pure lua replacement for https://github.com/github/copilot.vim
3+
This plugin is the pure lua replacement for [github/copilot.vim](https://github.com/github/copilot.vim).
44

5-
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.
5+
<details>
6+
<summary>Motivation behind `copilot.lua`</summary>
67

7-
## (IMPORTANT) Usage:
8+
While using `copilot.vim`, for the first time since I started using neovim my laptop began to overheat. Additionally,
9+
I found the large chunks of ghost text moving around my code, and interfering with my existing cmp ghost text disturbing.
10+
As lua is far more efficient and makes things easier to integrate with modern plugins, this repository was created.
11+
</details>
812

9-
Note that this plugin will only start up the copilot server. The current usage of this is via https://github.com/zbirenbaum/copilot-cmp, which turns copilot suggestions into menu entries for cmp, and displays the full text body in a float, similar to how documentation would appear, off to the side.
13+
## Install
1014

11-
On its own, this plugin will do nothing. You must either use https://github.com/zbirenbaum/copilot-cmp to make the server into a cmp source, or write your own plugin to interface with it, via the request and handler methods located in copilot.utils.lua
15+
Install the plugin with your preferred plugin manager.
16+
For example, with [packer.nvim](https://github.com/wbthomason/packer.nvim):
1217

13-
## Install
18+
```lua
19+
use { "zbirenbaum/copilot.lua" }
20+
```
1421

1522
### Authentication
1623

17-
Once copilot is started, run `:CopilotAuth` to start the authentication process.
24+
Once copilot is started, run `:Copilot auth` to start the authentication process.
1825

19-
### Setup
26+
## Setup and Configuration
2027

21-
You have to run the `require("copilot").setup(options)` function in order to start Copilot. If no options are provided, the defaults are used.
28+
You have to run the `require("copilot").setup(options)` function in order to start Copilot.
29+
If no options are provided, the defaults are used.
2230

23-
Because the copilot server takes some time to start up, I HIGHLY recommend that you load copilot after startup. This can be done in multiple ways, the best one will depend on your existing config and the speed of your machine:
31+
Because the copilot server takes some time to start up, It is recommend that you lazy load copilot.
32+
This can be done in multiple ways, the best one will depend on your existing config and the speed of your machine:
2433

25-
1. On 'VimEnter' + Defer: (My preferred method, works well with fast configs)
34+
1. On `VimEnter` event + defer (preferred method, works well with fast configs):
2635
```lua
2736
use {
2837
"zbirenbaum/copilot.lua",
29-
event = {"VimEnter"},
38+
event = "VimEnter",
3039
config = function()
3140
vim.defer_fn(function()
3241
require("copilot").setup()
3342
end, 100)
3443
end,
3544
}
3645
```
37-
2. Load After Statusline + defer: (If option (1) causes statusline to flicker, try this)
46+
47+
2. Load after statusline + defer (if option 1 causes statusline to flicker, try this):
3848
```lua
3949
use {
4050
"zbirenbaum/copilot.lua",
41-
after = 'feline.nvim', --whichever statusline plugin you use here
51+
after = "feline.nvim", -- whichever statusline plugin you use here
4252
config = function ()
43-
vim.defer_fn(function() require("copilot").setup() end, 100)
53+
vim.defer_fn(function()
54+
require("copilot").setup()
55+
end, 100)
4456
end,
4557
}
4658
```
47-
3. On 'InsertEnter': (The safest way to avoid statup lag. Note: Your copilot completions may take a moment to start showing up)
4859

60+
3. On `InsertEnter` event (safest way to avoid statup lag):
61+
Note: suggestions may take a moment to start showing up.
4962
```lua
5063
use {
5164
"zbirenbaum/copilot.lua",
5265
event = "InsertEnter",
5366
config = function ()
54-
vim.schedule(function() require("copilot").setup() end)
67+
vim.schedule(function()
68+
require("copilot").setup()
69+
end)
5570
end,
5671
}
5772
```
5873

59-
60-
#### Configuration
61-
6274
The following is the default configuration:
6375

6476
```lua
65-
panel = { -- no config options yet
66-
enabled = true,
67-
auto_refresh = false,
68-
keymap = {
69-
jump_prev = "[[",
70-
jump_next = "]]",
71-
accept = "<CR>",
72-
refresh = "gr",
73-
open = "<M-CR>"
77+
require('copilot').setup({
78+
panel = {
79+
enabled = true,
80+
auto_refresh = false,
81+
keymap = {
82+
jump_prev = "[[",
83+
jump_next = "]]",
84+
accept = "<CR>",
85+
refresh = "gr",
86+
open = "<M-CR>"
87+
},
88+
},
89+
suggestion = {
90+
enabled = true,
91+
auto_trigger = false,
92+
debounce = 75,
93+
keymap = {
94+
accept = "<M-l>",
95+
next = "<M-]>",
96+
prev = "<M-[>",
97+
dismiss = "<C-]>",
98+
},
7499
},
75-
},
76-
suggestion = {
77-
enabled = true,
78-
auto_trigger = false,
79-
debounce = 75,
80-
keymap = {
81-
accept = "<M-l>",
82-
next = "<M-]>",
83-
prev = "<M-[>",
84-
dismiss = "<C-]>",
100+
filetypes = {
101+
yaml = false,
102+
markdown = false,
103+
help = false,
104+
gitcommit = false,
105+
gitrebase = false,
106+
hgcommit = false,
107+
svn = false,
108+
cvs = false,
109+
["."] = false,
85110
},
86-
},
87-
filetypes = {
88-
yaml = false,
89-
markdown = false,
90-
help = false,
91-
gitcommit = false,
92-
gitrebase = false,
93-
hgcommit = false,
94-
svn = false,
95-
cvs = false,
96-
["."] = false,
97-
},
98-
copilot_node_command = 'node', -- Node version must be < 18
99-
plugin_manager_path = vim.fn.stdpath("data") .. "/site/pack/packer",
100-
server_opts_overrides = {},
111+
copilot_node_command = 'node', -- Node version must be < 18
112+
plugin_manager_path = vim.fn.stdpath("data") .. "/site/pack/packer",
113+
server_opts_overrides = {},
114+
})
101115
```
102116

103-
##### panel
117+
### panel
104118

105-
Enabling panel creates the `CopilotPanel` command, which allows you to preview suggestions
106-
in a split window.
119+
Panel can be used to preview suggestions in a split window. You can run the
120+
`:Copilot panel` command to open it.
107121

108122
If `auto_refresh` is `true`, the suggestions are refreshed as you type in the buffer.
109123

110-
##### suggestion
124+
The `copilot.panel` module exposes the following functions:
125+
126+
```lua
127+
require("copilot.panel").accept()
128+
require("copilot.panel").jump_next()
129+
require("copilot.panel").jump_prev()
130+
require("copilot.panel").open()
131+
require("copilot.panel").refresh()
132+
```
133+
134+
### suggestion
111135

112136
When `auto_trigger` is `true`, copilot starts suggesting as soon as you enter insert mode.
113137

@@ -129,8 +153,18 @@ cmp.event:on("menu_closed", function()
129153
end)
130154
```
131155

156+
The `copilot.suggestion` module exposes the following functions:
157+
158+
```lua
159+
require("copilot.suggestion").is_visible()
160+
require("copilot.suggestion").accept()
161+
require("copilot.suggestion").next()
162+
require("copilot.suggestion").prev()
163+
require("copilot.suggestion").dismiss()
164+
require("copilot.suggestion").toggle_auto_trigger()
165+
```
132166

133-
##### filetypes
167+
### filetypes
134168

135169
Specify filetypes for attaching copilot.
136170

@@ -157,7 +191,7 @@ require("copilot").setup {
157191
}
158192
```
159193

160-
##### copilot_node_command
194+
### copilot_node_command
161195

162196
Use this field to provide the path to a specific node version such as one installed by nvm. Node version must be < 18. The LTS version of node (16.17.0) is recommended.
163197

@@ -167,9 +201,9 @@ Example:
167201
copilot_node_command = vim.fn.expand("$HOME") .. "/.config/nvm/versions/node/v16.14.2/bin/node", -- Node version must be < 18
168202
```
169203

170-
##### plugin_manager_path
204+
### plugin_manager_path
171205

172-
This is installation path of Packer, change this to the plugin manager installation path of your choice
206+
This is installation path of Packer, change this to the plugin manager installation path of your choice.
173207

174208
Example:
175209

@@ -179,9 +213,11 @@ require("copilot").setup {
179213
}
180214
```
181215

182-
##### server_opts_overrides
216+
### server_opts_overrides
183217

184-
Override copilot lsp client settings. The `settings` field is where you can set the values of the options defined in SettingsOpts.md. These options are specific to the copilot lsp and can be used to customize its behavior. Ensure that the name field is not overriden as is is used for efficiency reasons in numerous checks to verify copilot is actually running. See `:h vim.lsp.start_client` for list of options.
218+
Override copilot lsp client settings. The `settings` field is where you can set the values of the options defined in [SettingsOpts.md](./SettingsOpts.md).
219+
These options are specific to the copilot lsp and can be used to customize its behavior. Ensure that the name field is not overriden as is is used for
220+
efficiency reasons in numerous checks to verify copilot is actually running. See `:h vim.lsp.start_client` for list of options.
185221

186222
Example:
187223

@@ -196,5 +232,15 @@ require("copilot").setup {
196232
}
197233
},
198234
}
199-
},
235+
}
200236
```
237+
238+
## Commands
239+
240+
`copilot.lua` defines the `:Copilot` command that can perform various actions. It has completion support, so try it out.
241+
242+
## Integrations
243+
244+
The `copilot.api` module can be used to build integrations on top of `copilot.lua`.
245+
246+
- [zbirenbaum/copilot-cmp](https://github.com/zbirenbaum/copilot-cmp): Integration with [`nvim-cmp`](https://github.com/hrsh7th/nvim-cmp).

0 commit comments

Comments
 (0)