Skip to content

Commit da9bdb9

Browse files
setup function and package manager independence fix
1 parent b20f595 commit da9bdb9

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,60 @@
22

33
This plugin is the pure lua replacement for 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+
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.
66

77
## (IMPORTANT) Usage:
8+
89
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.
910

1011
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
1112

1213
## Install
1314

1415
### Preliminary Steps
16+
1517
Currently, you must have had the original copilot.vim installed and set up at some point, as the authentication steps you do during its setup create files in ~/.config/github-copilot which copilot.lua must read from to function. Fairly soon, copilot.lua will be able to perform this authentication step on its own, but as the plugin is in early stages, this has not yet been fully implemented.
1618

17-
Install copilot.vim with `use {"github/copilot.vim"}`, `:PackerSync`, restart, and run `:Copilot` to be prompted for the necessary setup steps.
19+
Install copilot.vim with `use {"github/copilot.vim"}`, `:PackerSync`, restart, and run `:Copilot` to be prompted for the necessary setup steps.
1820

1921
After the setup steps are complete for copilot.vim, ensure that ~/.config/github-copilot has files in it, and then you are free to uninstall copilot.vim and proceed to the following steps.
2022

2123
### Setup
24+
25+
You have to run the `require("copilot").setup(options)` function in order to start Copilot. If no options are provided, the defaults are used.
26+
2227
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:
28+
2329
1. On 'InsertEnter': (My preferred way)
30+
2431
```
2532
use {
2633
"zbirenbaum/copilot.lua",
2734
event = "InsertEnter",
2835
config = function ()
29-
vim.schedule(function() require("copilot") end)
36+
vim.schedule(function() require("copilot").setup() end)
3037
end,
3138
},
3239
```
40+
3341
2. Load After Statusline + defer:
42+
3443
```
3544
["zbirenbaum/copilot.lua"] = {
3645
"zbirenbaum/copilot.lua",
3746
after = 'feline.nvim', --whichever statusline plugin you use here
3847
config = function ()
39-
vim.defer_fn(function() require("copilot") end, 100)
48+
vim.defer_fn(function() require("copilot").setup() end, 100)
4049
end,
4150
},
4251
```
4352

53+
#### Configuration
4454

55+
The following is the default configuration:
56+
57+
```lua
58+
{
59+
plugin_manager_path = vim.fn.stdpath("data") .. "/site/pack/packer", -- Installation Path of packer, change to the plugin manager installation path of your choice
60+
}
61+
```

lua/copilot/config.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
local M = {}
2+
3+
local defaults = {
4+
plugin_manager_path = vim.fn.stdpath("data") .. "/site/pack/packer",
5+
}
6+
7+
M.params = {}
8+
9+
M.setup = function(options)
10+
if not options then
11+
M.params = defaults
12+
else
13+
for key, value in pairs(defaults) do
14+
M.params[key] = options[key] or value
15+
end
16+
end
17+
end
18+
19+
return M

lua/copilot/init.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
require("copilot.copilot_handler").start()
1+
local config = require("copilot.config")
2+
local M = {}
3+
4+
M.setup = function (params)
5+
config.setup(params)
6+
config.params.plugin_manager_path = vim.fn.expand(config.params.plugin_manager_path) -- resolve wildcard and variable containing paths
7+
require("copilot.copilot_handler").start(config.params.plugin_manager_path)
8+
end
9+
10+
11+
return M

lua/copilot/util.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ M.get_completion_params = function()
2828
end
2929

3030
M.get_copilot_path = function(plugin_path)
31-
local root_path = plugin_path or vim.fn.stdpath("data")
32-
local packer_path = root_path .. "/site/pack/packer/"
33-
for _, loc in ipairs{"opt", "start"} do
34-
local copilot_path = packer_path .. loc .. "/copilot.lua/copilot/index.js"
31+
for _, loc in ipairs{"/opt", "/start", ""} do
32+
local copilot_path = plugin_path .. loc .. "/copilot.lua/copilot/index.js"
3533
if vim.fn.filereadable(copilot_path) ~= 0 then
3634
return copilot_path
3735
end

0 commit comments

Comments
 (0)