File tree Expand file tree Collapse file tree 3 files changed +40
-6
lines changed Expand file tree Collapse file tree 3 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -88,8 +88,11 @@ require('copilot').setup({
88
88
[" ." ] = false ,
89
89
},
90
90
copilot_node_command = ' node' , -- Node.js version must be > 18.x
91
- copilot_model = " " , -- Current LSP default is gpt-35-turbo, supports gpt-4o-copilot
92
91
workspace_folders = {},
92
+ copilot_model = " " , -- Current LSP default is gpt-35-turbo, supports gpt-4o-copilot
93
+ root_dir = function ()
94
+ return vim .fs .dirname (vim .fs .find (" .git" , { upward = true })[1 ])
95
+ end ,
93
96
server_opts_overrides = {},
94
97
})
95
98
```
@@ -228,6 +231,11 @@ workspace_folders = {
228
231
229
232
They can also be added runtime, using the command ` :Copilot workspace add [folderpath] ` where ` [folderpath] ` is the workspace folder.
230
233
234
+ ### root_dir
235
+
236
+ This allows changing the function that gets the root folder, the default looks for a parent folder that contains the folder ` .git ` .
237
+ If none is found, it will use the current working directory.
238
+
231
239
## Commands
232
240
233
241
` copilot.lua ` defines the ` :Copilot ` command that can perform various actions. It has completion support, so try it out.
Original file line number Diff line number Diff line change @@ -105,6 +105,9 @@ function M.buf_attach(force)
105
105
return
106
106
end
107
107
108
+ -- In case it has changed, we update it
109
+ M .config .root_dir = config .get_root_dir ()
110
+
108
111
local ok , client_id_or_err = pcall (lsp_start , M .config )
109
112
if not ok then
110
113
vim .notify (string.format (" [Copilot] Failed to start LSP client: %s" , client_id_or_err ), vim .log .levels .ERROR )
@@ -218,11 +221,7 @@ local function prepare_client_config(overrides)
218
221
[" copilot/openURL" ] = api .handlers [" copilot/openURL" ],
219
222
}
220
223
221
- local root_dir = vim .loop .cwd ()
222
- if not root_dir then
223
- root_dir = vim .fn .getcwd ()
224
- end
225
-
224
+ local root_dir = config .get_root_dir ()
226
225
local workspace_folders = {
227
226
--- @type workspace_folder
228
227
{
@@ -247,6 +246,7 @@ local function prepare_client_config(overrides)
247
246
end
248
247
end
249
248
249
+ -- LSP config, not to be confused with config.lua
250
250
return vim .tbl_deep_extend (" force" , {
251
251
cmd = {
252
252
node ,
Original file line number Diff line number Diff line change @@ -45,6 +45,10 @@ local default_config = {
45
45
server_opts_overrides = {},
46
46
--- @type string | nil
47
47
copilot_model = nil ,
48
+ --- @type function | string
49
+ root_dir = function ()
50
+ return vim .fs .dirname (vim .fs .find (" .git" , { upward = true })[1 ])
51
+ end ,
48
52
}
49
53
50
54
local mod = {
@@ -96,4 +100,26 @@ function mod.set(key, value)
96
100
mod .config [key ] = value
97
101
end
98
102
103
+ function mod .get_root_dir ()
104
+ if not mod .config then
105
+ error (" [Copilot] not initialized" )
106
+ end
107
+
108
+ local config_root_dir = mod .config .root_dir
109
+ local root_dir --[[ @as string]]
110
+
111
+ if type (config_root_dir ) == " function" then
112
+ root_dir = config_root_dir ()
113
+ else
114
+ root_dir = config_root_dir
115
+ end
116
+
117
+ if not root_dir or root_dir == " " then
118
+ root_dir = " ."
119
+ end
120
+
121
+ root_dir = vim .fn .fnamemodify (root_dir , " :p:h" )
122
+ return root_dir
123
+ end
124
+
99
125
return mod
You can’t perform that action at this time.
0 commit comments