feat(copilot): added copilot-native extra to setup native inline completions in Neovim

This commit is contained in:
Folke Lemaitre
2025-09-25 10:31:16 +02:00
parent 1d404815f0
commit 3b02963585
2 changed files with 85 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
---@diagnostic disable: missing-fields
if lazyvim_docs then
-- Native inline completions don't support being shown as regular completions
vim.g.ai_cmp = false
end
if LazyVim.has_extra("ai.copilot-native") then
if not vim.lsp.inline_completion then
LazyVim.error("You need Neovim >= 0.12 to use the `ai.copilot-native` extra.")
return {}
end
if LazyVim.has_extra("ai.copilot") then
LazyVim.error("Please disable the `ai.copilot` extra if you want to use `ai.copilot-native`")
return {}
end
end
vim.g.ai_cmp = false
return {
desc = "Native Copilot LSP integration. Requires Neovim >= 0.12",
-- copilot-language-server
{
"neovim/nvim-lspconfig",
opts = {
servers = {
copilot = {},
},
setup = {
copilot = function(_, opts)
vim.lsp.inline_completion.enable()
LazyVim.cmp.actions.ai_accept = function()
return vim.lsp.inline_completion.get()
end
end,
},
},
},
-- lualine
{
"nvim-lualine/lualine.nvim",
optional = true,
event = "VeryLazy",
opts = function(_, opts)
table.insert(opts.sections.lualine_x, 2, LazyVim.lualine.lsp("copilot"))
end,
},
}

View File

@@ -22,6 +22,42 @@ function M.status(icon, status)
}
end
--- Status indicator for LSP server activity
---@param server string
---@param opts? { methods?: string[], icon?: string }
function M.lsp(server, opts)
opts = opts or {}
local methods = opts.methods or { "textDocument/completion", "textDocument/inlineCompletion" }
local pending = {} ---@type table<number,true>
vim.api.nvim_create_autocmd("LspRequest", {
group = vim.api.nvim_create_augroup("lazyvim.lualine.lsp." .. server, { clear = true }),
callback = function(args)
---@class LspRequestData
---@field client_id number
---@field request { bufnr: number, method: string, type: "pending" | "cancel" | "complete" | string }
---@field request_id number
local data = args.data
local client = vim.lsp.get_client_by_id(data.client_id)
if client and client.name == server and vim.tbl_contains(methods, data.request.method) then
pending[data.request_id] = data.request.type == "pending" or nil
end
end,
})
return {
function()
return opts.icon
or LazyVim.config.icons.kinds[server:sub(1, 1):upper() .. server:sub(2)]
or LazyVim.config.icons.diagnostics.Hint
end,
cond = function()
return #vim.lsp.get_clients({ name = server, bufnr = 0 }) > 0
end,
color = function()
return { fg = Snacks.util.color(vim.tbl_isempty(pending) and "Special" or "DiagnosticWarn") }
end,
}
end
---@param name string
---@param icon? string
function M.cmp_source(name, icon)