copilot.lua
copilot.lua copied to clipboard
Copilot panel conflicts with file auto-save
When I open Copilot panel with meta+enter, it hangs on the loading message forever.
This is due to a conflict with the following snippet:
-- Autosave when losing focus
vim.api.nvim_create_autocmd({ "FocusLost", "BufLeave" }, {
callback = function()
if vim.bo.modified and not vim.bo.readonly and vim.fn.expand("%") ~= "" and vim.bo.buftype == "" then
vim.api.nvim_command("silent! write")
end
end,
})
Given how frequent this kind of snippet is, I think it would be nice if they both played along.
Here's a full init.lua to reproduce the problem:
vim.g.mapleader = ","
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
error("Error cloning lazy.nvim:\n" .. out)
end
end
-- Autosave when losing focus
vim.api.nvim_create_autocmd({ "FocusLost", "BufLeave" }, {
callback = function()
if vim.bo.modified and not vim.bo.readonly and vim.fn.expand("%") ~= "" and vim.bo.buftype == "" then
vim.api.nvim_command("silent! write")
end
end,
})
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
{
"zbirenbaum/copilot.lua",
cmd = "Copilot",
event = "InsertEnter",
config = function()
require("copilot").setup({})
end,
},
})