Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ec9922e
feat: update to latest copilot.vim/dist
AntoineGS Mar 12, 2025
061fd4f
feat: use allow changing the copilot model used
AntoineGS Mar 12, 2025
f5b9523
feat: initial support for workspaces
AntoineGS Mar 15, 2025
1c63ea5
refactor: autoformat changes, add typing for LSP, fix typo
AntoineGS Mar 15, 2025
2abd5ae
refactor: slightly improve startup error handling for better context …
AntoineGS Mar 15, 2025
11970ea
refactor: improve error message
AntoineGS Mar 15, 2025
b9ad169
fix: add missing copilot_model definition in config
AntoineGS Mar 16, 2025
6f16292
Merge branch 'gpt4o' into workspaceFolders
AntoineGS Mar 16, 2025
5d3c8aa
fix: missing copilot.lua version
AntoineGS Mar 16, 2025
827f1a1
Merge branch 'upgrade_copilot.vim' into gpt4o
AntoineGS Mar 16, 2025
c659294
Merge branch 'gpt4o' into workspaceFolders
AntoineGS Mar 16, 2025
3718ae5
refactor: resolve all Lua LSP warnings
AntoineGS Mar 16, 2025
97cd020
feat: add support for dynamic root_dir resolving
AntoineGS Mar 16, 2025
863b40a
fix: add missing capability for workspaces
AntoineGS Mar 18, 2025
4026e44
Merge branch 'workspaceFolders' into warning_cleanup
AntoineGS Mar 18, 2025
e5b5400
Merge branch 'warning_cleanup' into dynamic_root_dir
AntoineGS Mar 18, 2025
7b6b208
fix: :Copilot auth would not work with table.unpack, reverting
AntoineGS Mar 20, 2025
4c689d2
Merge branch 'master' into workspaceFolders
AntoineGS Mar 21, 2025
b9c3101
Merge branch 'workspaceFolders' into warning_cleanup
AntoineGS Mar 21, 2025
4007882
Merge branch 'warning_cleanup' into dynamic_root_dir
AntoineGS Mar 21, 2025
654e6a0
fix: use root_dir instead of get_root_dir
AntoineGS Mar 21, 2025
d8a3ca7
Merge branch 'master' into dynamic_root_dir
AntoineGS Mar 21, 2025
8b13458
move a few things around
AntoineGS Mar 21, 2025
3c97812
Update readme
AntoineGS Mar 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ require('copilot').setup({
["."] = false,
},
copilot_node_command = 'node', -- Node.js version must be > 18.x
copilot_model = "", -- Current LSP default is gpt-35-turbo, supports gpt-4o-copilot
workspace_folders = {},
copilot_model = "", -- Current LSP default is gpt-35-turbo, supports gpt-4o-copilot
root_dir = function()
return vim.fs.dirname(vim.fs.find(".git", { upward = true })[1])
end,
server_opts_overrides = {},
})
```
Expand Down Expand Up @@ -228,6 +231,11 @@ workspace_folders = {

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.

## Commands

`copilot.lua` defines the `:Copilot` command that can perform various actions. It has completion support, so try it out.
Expand Down
10 changes: 5 additions & 5 deletions lua/copilot/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ function M.buf_attach(force)
return
end

-- In case it has changed, we update it
M.config.root_dir = config.get_root_dir()

local ok, client_id_or_err = pcall(lsp_start, M.config)
if not ok then
vim.notify(string.format("[Copilot] Failed to start LSP client: %s", client_id_or_err), vim.log.levels.ERROR)
Expand Down Expand Up @@ -218,11 +221,7 @@ local function prepare_client_config(overrides)
["copilot/openURL"] = api.handlers["copilot/openURL"],
}

local root_dir = vim.loop.cwd()
if not root_dir then
root_dir = vim.fn.getcwd()
end

local root_dir = config.get_root_dir()
local workspace_folders = {
--- @type workspace_folder
{
Expand All @@ -247,6 +246,7 @@ local function prepare_client_config(overrides)
end
end

-- LSP config, not to be confused with config.lua
return vim.tbl_deep_extend("force", {
cmd = {
node,
Expand Down
26 changes: 26 additions & 0 deletions lua/copilot/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ local default_config = {
server_opts_overrides = {},
---@type string|nil
copilot_model = nil,
---@type function|string
root_dir = function()
return vim.fs.dirname(vim.fs.find(".git", { upward = true })[1])
end,
}

local mod = {
Expand Down Expand Up @@ -96,4 +100,26 @@ function mod.set(key, value)
mod.config[key] = value
end

function mod.get_root_dir()
if not mod.config then
error("[Copilot] not initialized")
end

local config_root_dir = mod.config.root_dir
local root_dir --[[@as string]]

if type(config_root_dir) == "function" then
root_dir = config_root_dir()
else
root_dir = config_root_dir
end

if not root_dir or root_dir == "" then
root_dir = "."
end

root_dir = vim.fn.fnamemodify(root_dir, ":p:h")
return root_dir
end

return mod