feat: copilot.nvim

This commit is contained in:
Folke Lemaitre
2025-09-26 12:12:47 +02:00
parent 92b7fcf7b1
commit 493e8666a6

View File

@@ -16,7 +16,6 @@ if LazyVim.has_extra("ai.copilot-native") then
end
vim.g.ai_cmp = false
local status = {} ---@type table<number, "ok" | "error" | "pending">
return {
desc = "Native Copilot LSP integration. Requires Neovim >= 0.12",
@@ -26,17 +25,6 @@ return {
opts = {
servers = {
copilot = {
handlers = {
didChangeStatus = function(err, res, ctx)
if err then
return
end
status[ctx.client_id] = res.kind ~= "Normal" and "error" or res.busy and "pending" or "ok"
if res.status == "Error" then
LazyVim.error("Please use `:LspCopilotSignIn` to sign in to Copilot")
end
end,
},
-- stylua: ignore
keys = {
{
@@ -60,6 +48,11 @@ return {
-- Accept inline suggestions or next edits
LazyVim.cmp.actions.ai_accept = function()
local Nes = require("copilot.nes")
if Nes.have() and (Nes.jump() or Nes.apply()) then
return true
end
if vim.lsp.inline_completion.get() then
-- nes_update() -- ensure nes update is triggered after inline completion
return true
@@ -80,10 +73,26 @@ return {
opts.sections.lualine_x,
2,
LazyVim.lualine.status(LazyVim.config.icons.kinds.Copilot, function()
local clients = vim.lsp.get_clients({ name = "copilot", bufnr = 0 })
return #clients > 0 and status[clients[1].id] or nil
local status = require("copilot.status").get()
if status then
return status.kind == "Error" and "error" or status.busy and "pending" or "ok"
end
end)
)
end,
},
{
"folke/copilot.nvim",
init = function()
LazyVim.cmp.actions.ai_stop = function()
require("copilot").hide()
end
end,
opts = {},
keys = {
-- nes is also useful in normal mode
{ "<tab>", LazyVim.cmp.map({ "ai_accept" }, "<tab>"), mode = { "n" }, expr = true },
},
} or nil,
}